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

math.isFinite missing #501

Open
juancarlospaco opened this issue Dec 29, 2020 · 5 comments
Open

math.isFinite missing #501

juancarlospaco opened this issue Dec 29, 2020 · 5 comments

Comments

@juancarlospaco
Copy link
Collaborator

juancarlospaco commented Dec 29, 2020

math is missing the maximum representable finite float that is not +Inf (but math has the minimum).
It is not the same as +MinFloatNormal.

I dont know if this is correct:

const MaxFloatNormal* = 1.7976931348623157e+308   ## Maximum representable finite `float`.

People find this useful, to check that your float did not gone Inf.

Other langs

@timotheecour
Copy link
Owner

timotheecour commented Dec 29, 2020

nim --eval:'import fenv; echo float.maximumPositiveValue'
1.797693134862316e+308

but maybe docs can improve cross-referencing

also this doc comment seems not the best description:

fenv module for handling of floating-point rounding and exceptions (overflow, zero-divide, etc.)

@juancarlospaco
Copy link
Collaborator Author

OK, maybe I am wrong, but then why MinFloatNormal is on math but not the Maximum?. 🤔

@timotheecour
Copy link
Owner

actually they're different:

nim --eval:'import fenv,math; echo float.minimumPositiveValue - MinFloatNormal'
4.940656458412465e-324

I'd rather not introduce an alias, but I'm all in favor for cross-referencing, and explaining in doc comment the difference.

@juancarlospaco
Copy link
Collaborator Author

juancarlospaco commented Dec 30, 2020

I seen is important for end users to check if their float gone -Inf or +Inf, maybe 1 tiny proc to check can be added, isInf() ?.

@timotheecour
Copy link
Owner

timotheecour commented Dec 30, 2020

let's add math.isFinite instead (logical to add after isNaN)

found in lots of langs:
https://dlang.org/library/std/math/is_finite.html
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isFinite
http://www.cplusplus.com/reference/cmath/isfinite/
https://numpy.org/doc/stable/reference/generated/numpy.isfinite.html
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/is-finite.html

isInfinite is less common IIUC (note that it's not opposite of isFinite because of NaN), because it's probably not more efficient than a == Inf or a == -Inf

@timotheecour timotheecour mentioned this issue Dec 30, 2020
1 task
@juancarlospaco juancarlospaco changed the title math.MaxFloatNormal missing const math.isFinite missing Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants