I was wondering, that what is the closest value to the Zero floating point types can hold, it could be handy to try to kill the code that compares to zero wrongly in the Unit Tests.

I was wondering, that what is the closest value to the Zero floating point types can hold, it could be handy to try to kill the code that compares to zero wrongly in the Unit Tests. 

How I get the constants for those? Or is those already defined in somewhere?

Comments

  1. I would say it is rather because it is not simple, and fixed point is not simple either once you get beyond addition/subtraction.

    Numerics are an area of compromises, and there are no magic bullets.

    Case in point: we can give Tommi Prami no answer without knowing his domain, and even knowing it, there may not be a definite answer (cf. Asbjørn Heid case). And if the goal is to just test a bunch of math routines, then the proper precision testing becomes... an interesting problem.

    There are many other examples: from Kahan summation to solving linear systems, when you need numeric precision, complexity invites itself.

    ReplyDelete
  2. Indeed Eric Grange. Another example to illustrate:

    A user had managed to generate a scene which made our code produce lots of NaN (not-a-number) values (or +inf, I can't recall but it doesn't matter).

    To make a long debugging story short, the issue was that one of our devs had written an expression like this

      r := (a * b * c) / (x * y * z);

    because he wanted to preserve precision as much as possible, because "as we all know", you can lose precision doing floating point divisions too early.

    However it turned out that in certain cases, all those factors could be very small so that when multiplying them together the numerator and denominator could become denormalized.

    By studying the math behind the expression I could pair each factor so that the ratio of each pair was roughly one. Thus we ended up with the following code

      r:= (a / y) * (b / x) * (c / z);

    which was much more stable.

    ReplyDelete
  3. Asbjørn Heid I managed to produce NaN without the help of a client. When creating Euler-Angles from a LocalMatrix in FMX, I pass one member of the matrix to the ArcSin function. It is usually expected that members of the Matrix (type single) are always between -1 and +1, but you have to check for this and clamp values prior to calling ArcSin. All I did was rotating some objects...

    ReplyDelete

Post a Comment