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

isNaN function #164

Closed
pxqr opened this issue Apr 29, 2014 · 4 comments
Closed

isNaN function #164

pxqr opened this issue Apr 29, 2014 · 4 comments
Milestone

Comments

@pxqr
Copy link

pxqr commented Apr 29, 2014

Sometimes we need to test if some values are NaNs, for instance we might want to filter NaNs out from an array. The following function works with both CUDA and Interpreter backends:

isNaN :: (IsScalar a, Elt a) => Exp a -> Exp Bool
isNaN x = x /=* x 

Should it work with every IEEE 754 compliant backend or it must be defined as primitive operation?

@robeverest
Copy link
Member

I believe that definition of isNaN is part of the IEEE 754 spec, or at least the rule that says NaN is not equal to anything, including itself, is.

Whether it should be defined as a primitive operation really depends on whether backends could provide a more efficient implementation.

@tmcdonell
Copy link
Member

It might be a good opportunity to add a few similar functions from the RealFloat class, like isInfinite. Currently there is no way to test/represent exceptional values (ping #136).

@andygill
Copy link

andygill commented May 1, 2014

Have a look at @conal’s boolean package on hackage. Data.Boolean.Numbers, written by @jbracker, gives a deep embedding overloading for the Haskell number classes. We used it in Sunroof. It may or may not work for you, but no sense in reinventing the wheel.

@tmcdonell tmcdonell added this to the 1.0 release milestone May 9, 2014
@tmcdonell
Copy link
Member

There are still missing functions from RealFrac and RealFloat, but isNan exists now (thanks @mikusp!) so I'll close this ticket.

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

5 participants
@andygill @robeverest @tmcdonell @pxqr and others