WojciechMula / toys

Storage for my snippets, toy programs, etc.
BSD 2-Clause "Simplified" License
316 stars 38 forks source link

floor() is actually trunc() #19

Open MrUnbelievable92 opened 1 year ago

MrUnbelievable92 commented 1 year ago

As the title says, the 'double custom_floor(const double x)' function actually truncates negative values, not apply the mathematical floor function, which would for instance result in -15 given -14.5 as an input. This is also true for SSE4, where floor is defined as rounding towards negative infinity. The 'custom_floor' function rounds toward zero.

Also, it doesn't handle infinity and NaN as input, which only results in 'MOVQ', 'TEST' 'CMOVAE' as ouput instructions resulting in 1 additional cycle in latency, but I guess that's a design choice.