32bit NaN check

671 views
Skip to first unread message

simon place

unread,
Jun 16, 2013, 7:21:56 PM6/16/13
to golan...@googlegroups.com
i was looking to check for a vary rare situation when i get NaN, its deep in some computation that i don't want to rearrange to preclude it.

so i want to check for it, but i seem to need to add the Math package, and convert to 64bit, this is a very high price to pay for something that comes up less than 1 in 10e7+ cases, is there some other way? ( i was surprised there isn't a 32bit isNaN(). )

Matthew Kane

unread,
Jun 16, 2013, 7:26:32 PM6/16/13
to simon place, golang-nuts

The NaN check is simply return f != f.

On Jun 16, 2013 7:22 PM, "simon place" <simon...@googlemail.com> wrote:
i was looking to check for a vary rare situation when i get NaN, its deep in some computation that i don't want to rearrange to preclude it.

so i want to check for it, but i seem to need to add the Math package, and convert to 64bit, this is a very high price to pay for something that comes up less than 1 in 10e7+ cases, is there some other way? ( i was surprised there isn't a 32bit isNaN(). )

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

simon place

unread,
Jun 16, 2013, 8:04:08 PM6/16/13
to golan...@googlegroups.com, simon place
thanks, never would have guessed that.

i'll see what that does for speed, a bit poor on readability though so i guess i'll just add a comment.

Dan Kortschak

unread,
Jun 16, 2013, 8:15:13 PM6/16/13
to simon place, golan...@googlegroups.com
... or add and call:

func isNaN(f float32) bool { return f != f }

simon place

unread,
Jun 16, 2013, 8:28:19 PM6/16/13
to golan...@googlegroups.com, simon place
yes, and it will probably be in-lined for no speed penalty?

Dave Cheney

unread,
Jun 16, 2013, 8:34:22 PM6/16/13
to simon place, golang-nuts
Yup, should do.
http://dave.cheney.net/2012/02/11/how-the-go-language-improves-expressiveness-without-sacrificing-runtime-performance

On Mon, Jun 17, 2013 at 10:28 AM, simon place
<simon...@googlemail.com> wrote:
> yes, and it will probably be in-lined for no speed penalty?
>
Reply all
Reply to author
Forward
0 new messages