Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses Math, CastleVectors;
- var
- F, F2, F3: Single;
- begin
- F := Nan;
- F2 := Nan;
- { Doing some operations on Nan values produces "Invalid floating point operation".
- (Unless the FPU exceptions are masked out. Which happens to be always true when
- a program uses OpenGL, FPC GL unit has to mask out exceptions to protect from
- OpenGL implementations producing FPU errors.)
- So below we explicitly silence them by Math.ClearExceptions(false). }
- Writeln(F = F2); // true
- Math.ClearExceptions(false);
- Writeln(FloatsEqual(F, F2)); // false (reason explained below)
- Math.ClearExceptions(false);
- F3 := F - F2; // Nan, because subtracting Nans is Nan
- Math.ClearExceptions(false);
- Writeln(F3);
- F3 := Abs(F3); // Nan, because Abs(Nan) is Nan
- Math.ClearExceptions(false);
- Writeln(F3);
- Writeln(F3 < 0.1); // false, because comparing using < or > normal number with Nan is false
- Math.ClearExceptions(false);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement