Skip to main content

fposmod

Function fposmod 

pub fn fposmod(x: f64, y: f64) -> f64
Expand description

Returns the floating-point modulus of x divided by y, wrapping equally in positive and negative.

print(" (x)  (fmod(x, 1.5))   (fposmod(x, 1.5))")
for i in 7:
	var x = i * 0.5 - 1.5
	print("%4.1f           %4.1f  | %4.1f" % [x, fmod(x, 1.5), fposmod(x, 1.5)])

Prints:

 (x)  (fmod(x, 1.5))   (fposmod(x, 1.5))
-1.5           -0.0  |  0.0
-1.0           -1.0  |  0.5
-0.5           -0.5  |  1.0
 0.0            0.0  |  0.0
 0.5            0.5  |  0.5
 1.0            1.0  |  1.0
 1.5            0.0  |  0.0