mmp / pbrt-v3

Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
http://pbrt.org
BSD 2-Clause "Simplified" License
4.86k stars 1.18k forks source link

Question about Comparison between Floating-Point Number #308

Closed kanition closed 3 years ago

kanition commented 3 years ago

Thank you for your amazing work! I'm learning it by myself.

I find there are different ways to compare floating-point numbers:

  1. Using function CHECK_NE or others like it: https://github.com/mmp/pbrt-v3/blob/aaa552a4b9cbf9dccb71450f47b268e0ed6370e2/src/core/geometry.h#L252 But I couldn't found the definition of CHECK_NE. What's its implementation?

  2. Using == or != directly: https://github.com/mmp/pbrt-v3/blob/aaa552a4b9cbf9dccb71450f47b268e0ed6370e2/src/core/transform.h#L149 https://github.com/mmp/pbrt-v3/blob/aaa552a4b9cbf9dccb71450f47b268e0ed6370e2/src/core/transform.h#L64 Why is the common way below not used here? Is there any special reason?

    #define EPSILON 0.000000000001
    Float f = 0.0;
    if (f < EPSILON && f > -EPSILON)
    {
    //f == 0, do something
    }
    else
    {
    //f != 0, do something
    }

What's the scope of application of the strict equality and approximate equality in pbrt?