add Round: returns the float32/float64 of specified precision#529
Open
freeeverett wants to merge 1 commit intosamber:masterfrom
Open
add Round: returns the float32/float64 of specified precision#529freeeverett wants to merge 1 commit intosamber:masterfrom
freeeverett wants to merge 1 commit intosamber:masterfrom
Conversation
samber
reviewed
Sep 9, 2024
math.go
Outdated
| } | ||
| } | ||
| pow10N := math.Pow10(nn) | ||
| return T(math.Round(float64(f)*pow10N) / pow10N) |
Owner
There was a problem hiding this comment.
use this instead:
integer, fractional := math.Modf(nbr)
total := integer + math.Round(fractional*pow10N)/pow10Nbecause doing math.Round(float64(f)*pow10N) / pow10N might lead to interger overflow
samber
reviewed
Sep 9, 2024
samber
reviewed
Sep 9, 2024
Author
|
I'm sorry, I have modified the description of Round to better fit the purpose of the function |
Author
|
And, I added a Truncate function |
samber
reviewed
Sep 19, 2024
math.go
Outdated
| return T(math.Round(float64(f)*pow10N) / pow10N) | ||
| } | ||
|
|
||
| // Truncate returns the float32/float64 of the specified precision |
Owner
|
why did you close the pr ? misclick ? Can you please add these helpers to the readme? |
Author
|
I encountered a tricky problem and didn't have enough time to solve it, so I closed it. However, now I have plenty of time to start solving the problem |
dae8014 to
e49edd2
Compare
Author
|
There are still some issues with these submissions, I will resolve them as soon as possible |
57d9663 to
0237473
Compare
…m rounding half away. Add Truncate: returns the float32/float64 of the specified precision from truncated.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.