3 ms·
This article essentially describes a modulo (%) operator for floats, which is well-defined and completely analogous to the integer modulo operation. I always wo
by vog 9y ago
This article essentially describes a modulo (%) operator for floats, which is well-defined and completely analogous to the integer modulo operation. I always wondered why these aren't part of the FPU command set, or at least part of modern programming languages, e.g.:
1.0 % 5.0 = 1.0
6.0 % 5.0 = 1.0
7.0 % 5.0 = 2.0
7.4 % 5.0 = 2.4
7.4 % 1.0 = 0.4
With that in place, the torodial distance becomes a one-liner without any case distinctions (i.e. without ifs).
- mkl 9y ago> I always wondered why these aren't part of the FPU command set, or at least part of modern programming languages They are a part of modern (and not-so-modern) programming languages (% in Python, Rust, etc.). Even C from quarter of a century ago supports them (fmod). There are also at least two CPU instructions on x86, fprem and fprem1.
- sp332 9y agoI couldn't even find an integer modulus operation when I was porting my fractal code to WebGL. https://www.shadertoy.com/view/MdSXWc https://www.shadertoy.com/view/MdSXWc
- TrinaryWorksToo 9y agoDid the % operator not work? I just tested 1 % 10 and it seemed to compile. I used the % operator in other shaders. Remember that WebGL is ultimately a sub and superset of C.