-
-
Notifications
You must be signed in to change notification settings - Fork 823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add Round: returns the float32/float64 of specified precision #529
base: master
Are you sure you want to change the base?
Conversation
math.go
Outdated
} | ||
} | ||
pow10N := math.Pow10(nn) | ||
return T(math.Round(float64(f)*pow10N) / pow10N) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use this instead:
integer, fractional := math.Modf(nbr)
total := integer + math.Round(fractional*pow10N)/pow10N
because doing math.Round(float64(f)*pow10N) / pow10N
might lead to interger overflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
up?
I'm sorry, I have modified the description of Round to better fit the purpose of the function |
And, I added a Truncate function |
return T(math.Round(float64(f)*pow10N) / pow10N) | ||
} | ||
|
||
// Truncate returns the float32/float64 of the specified precision |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment than above
why did you close the pr ? misclick ? Can you please add these helpers to the readme? |
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 |
… specified precision add Truncate: returns the float32/float64 of the specified precision
There are still some issues with these submissions, I will resolve them as soon as possible |
No description provided.