Skip to content

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?

@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

math.go Outdated
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

@freeeverett freeeverett force-pushed the master branch 2 times, most recently from dae8014 to e49edd2 Compare October 7, 2024 14:43
@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
@freeeverett freeeverett marked this pull request as ready for review January 15, 2025 09:50
@freeeverett freeeverett force-pushed the master branch 2 times, most recently from 57d9663 to 0237473 Compare January 15, 2025 10:00
…m rounding half away.

Add Truncate: returns the float32/float64 of the specified precision from truncated.
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