Skip to content
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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

freeeverett
Copy link

No description provided.

math.go Outdated
}
}
pow10N := math.Pow10(nn)
return T(math.Round(float64(f)*pow10N) / pow10N)
Copy link
Owner

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

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

up?

math_test.go Show resolved Hide resolved
@freeeverett
Copy link
Author

I'm sorry, I have modified the description of Round to better fit the purpose of the function

@freeeverett
Copy link
Author

And, I added a Truncate function

return T(math.Round(float64(f)*pow10N) / pow10N)
}

// Truncate returns the float32/float64 of the specified precision
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment than above

@samber
Copy link
Owner

samber commented Sep 19, 2024

why did you close the pr ?

misclick ?

Can you please add these helpers to the readme?

@freeeverett
Copy link
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

… specified precision

add Truncate: returns the float32/float64 of the specified precision
@freeeverett
Copy link
Author

freeeverett commented Oct 12, 2024

There are still some issues with these submissions, I will resolve them as soon as possible

@freeeverett freeeverett marked this pull request as draft October 12, 2024 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants