The Wayback Machine - https://web.archive.org/web/20210716192832/https://github.com/unisonweb/unison/issues/2243
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 Float.isNaN and related Float predicates #2243

Open
philderbeast opened this issue Jul 16, 2021 · 5 comments
Open

Add Float.isNaN and related Float predicates #2243

philderbeast opened this issue Jul 16, 2021 · 5 comments

Comments

@philderbeast
Copy link
Contributor

@philderbeast philderbeast commented Jul 16, 2021

If someone looks at this, it might also be a good moment to consider whether we should be able to parse or pretty-print float values Infinity, -Infinity and NaN. (comment)

Originally posted by @atacratic in #611 (comment)

@philderbeast
Copy link
Contributor Author

@philderbeast philderbeast commented Jul 16, 2021

Can we please add predicate functions to Float that test for +Infinity, -Infinity and NaN. Haskell's GHC does it with FFI calls.

@pchiusano
Copy link
Member

@pchiusano pchiusano commented Jul 16, 2021

Good idea.

I think we can just have Float.Infinity : Float and Float.NegativeInfinity : Float and Float.NaN as builtins, and then the pretty-printer can use the names for these builtins when printing floats.

@pchiusano
Copy link
Member

@pchiusano pchiusano commented Jul 16, 2021

https://github.com/unisonweb/unison/blob/trunk/docs/adding-builtins.markdown is (I think?) mostly up to date if you feel like having a go at this one. :)

@philderbeast
Copy link
Contributor Author

@philderbeast philderbeast commented Jul 16, 2021

These comments from primFloat.c say how to test for these:

   /* Floating point NaN iff exponent is all ones, mantissa is
      non-zero (but see below.) */

    /* A float is Inf iff exponent is max (all ones),
       and mantissa is min(all zeros.) */

    /* A (single/double/quad) precision floating point number
       is denormalised iff:
        - exponent is zero
	- mantissa is non-zero.
        - (don't care about setting of sign bit.)
    */

    /* sign (bit 31) set (only) => negative zero */
@pchiusano
Copy link
Member

@pchiusano pchiusano commented Jul 16, 2021

@philderbeast ah that's a good point, if we just have a bitwise cast from Float to Nat then we can just write these in pure unison. I think I like that better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants