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

SRFI 144: fl-least should not be negative #831

Closed
jpellegrini opened this issue May 13, 2022 · 1 comment
Closed

SRFI 144: fl-least should not be negative #831

jpellegrini opened this issue May 13, 2022 · 1 comment

Comments

@jpellegrini
Copy link
Contributor

jpellegrini commented May 13, 2022

Hello,

Chibi implements fl-least as -DBL_MAX (lib/srfi/144/math.stub, line 46), but the SRFI says it should be the smallest positive finite flonum (so it's not -DBL_MAX, but rather DBL_TRUE_MIN).
However: this breaks compatibility with OpenBSD, since DBL_TRUE_MIN isn't there yet.
Using DBL_MIN would discard subnormal numbers which are less than DBL_MIN (and the SRFI recommends DBL_TRUE_MIN).

Maybe relevant:

  • I see Gauche forces the encoding of a flonum with an ad-hoc procedure,
(define-constant fl-least     (encode-float '#(1 -1074 1)))

(It's in ext/scheme/flonum.scm, line 123)

  • I have used DBL_TRUE_MIN in STklos, but it won't compile on OpenBSD.

  • The Chicken egg, srfi-144 seems to use DBL_TRUE_MIN also.

@jpellegrini
Copy link
Contributor Author

If you trust that all supported platforms will always use IEEE 754-encoded floating numbers, one way to get DBL_TRUE_MIN is to make a properly-sized (32 or 64-bit) unsigned integer equal to one. That would give you a zero exponent, zero sign bit and a one in the mantissa (which is exactly what DBL_TRUE_MIN should be).

Or you could take DBL_MIN and keep dividing it by 2.0 until it becomes zero. The last non-zero number should be DBL_TRUE_MIN (this is what I think Sagittarius does, and what I have included in a PR for STklos).

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

No branches or pull requests

2 participants