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

NaN check implementation in math32.Ray not working #164

Open
burner-account opened this issue Jan 21, 2020 · 0 comments
Open

NaN check implementation in math32.Ray not working #164

burner-account opened this issue Jan 21, 2020 · 0 comments

Comments

@burner-account
Copy link

burner-account commented Jan 21, 2020

Description:

In order to compare calculation results to NaN, at least the math32.Ray does the following, e.g. in func(*Ray) IntersectPlane(...)

	t := ray.DistanceToPlane(plane)
	if t == NaN() {
		return nil
	}

Bug:
Comparing NaNs by value does not work. Those NaNs are IEEE 754 NaNs afaik, meaning the exponent bits are all 1 and the mantissa bits are non-zero. So, comparing by value might work (same mantissa) but it would be a rare exception.

You may try math32.NaN() == math32.NaN() if you like, or math.Log(-1.0) == math.Log(-1.0).
Playground

Possible solution:
NaN-checks in golang can use the math.IsNaN(float64) function.
It is possible to extend the math32 by

func IsNaN(subj float32) bool {
    return math.IsNaN(float64(subj))
}

This func should be used everywhere a check against NaN has to be performed.

A quick search for == NaN() and == math32.NaN() only returned the code in Ray.IntersectPlane, so maybe this bug does not hurt that much.

Edit:
As math32 already has such a IsNaN() function, it only has to be used.

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

1 participant