### Post by strace3184 on Nov 22, 2020 17:44:56 GMT

I'm at the end of chapter 10, and I'm experiencing noise when I apply a checkerboard pattern to the planes.

I'm pretty sure this is what in a previous chapter is described as acne, due to floating point errors causing values to inconsistency fall behind and above a threshold.

For example, if translate the floor plane by a small amount, say 0.01 world points, the noise disappears.

The formula I'm using is:

`(x.floor() + y.floor() + z.floor()) as i32 % 2 == 0`

In order to get a simple test case, it's enough to use only y:

`point.y.floor() as i32 % 2 == 0`

The noise can be observed from the computations; see this small sample:

y: 0.0000000000000000000000000000, floor: 0.0000000000000000000000000000, i32:0, mod_is_0:true

y: 0.0000000000000000000000000000, floor: 0.0000000000000000000000000000, i32:0, mod_is_0:true

y: 0.0000000000000000000000000000, floor: 0.0000000000000000000000000000, i32:0, mod_is_0:true

y: 0.0000000000000000000000000000, floor: 0.0000000000000000000000000000, i32:0, mod_is_0:true

y: 0.0000000000000000000000000000, floor: 0.0000000000000000000000000000, i32:0, mod_is_0:true

y: 0.0000000000000000000000000000, floor: 0.0000000000000000000000000000, i32:0, mod_is_0:true

y: 0.0000000000000000000000000000, floor: 0.0000000000000000000000000000, i32:0, mod_is_0:true

y: 0.0000000000000000000000000000, floor: 0.0000000000000000000000000000, i32:0, mod_is_0:true

y:-0.0000000000000004440892098501, floor:-1.0000000000000000000000000000, i32:0, mod_is_0:false

y:-0.0000000000000004440892098501, floor:-1.0000000000000000000000000000, i32:0, mod_is_0:false

y: 0.0000000000000000000000000000, floor: 0.0000000000000000000000000000, i32:0, mod_is_0:true

y: 0.0000000000000000000000000000, floor: 0.0000000000000000000000000000, i32:0, mod_is_0:true

y:-0.0000000000000004440892098501, floor:-1.0000000000000000000000000000, i32:0, mod_is_0:false

y:-0.0000000000000008881784197001, floor:-1.0000000000000000000000000000, i32:0, mod_is_0:false

note the noise, where `zero:false`.

I can work this around by considering individual values smaller than epsilon to be zero:

`let x = if .x.abs() < EPSILON { 0.0 } else { x };`

let y = if .y.abs() < EPSILON { 0.0 } else { y };

let z = if .z.abs() < EPSILON { 0.0 } else { z };

(I'm inspecting and optionally resetting the values individually, because otherwise the error would sum)

and then computing as before:

`let use_color_a = (x.floor() + y.floor() + z.floor()) as i32 % 2 == 0;`

Is this an appropriate way, or there is a simpler/better/more appropriate one?