The following code should output "3" but instead outputs "0". This is because, regardless of the values sent to std.math.modf, the returned value is always 0. I've used many combinations of values, but the result is always the same: 0. At first I believed I was misusing the function and I noticed that the second parameter was taken as a ref, so I performed the function call and checked 'b', but it always stored the beginning value unchanged.
import std.stdio;
import std.math;
void main ()
{
real a = 9.,
b = 5.;
writeln(modf(a,b));
}
Comment #1 by etherous — 2010-08-29T19:33:57Z
Typo: Should return 4, not 3
Comment #2 by braddr — 2011-02-06T15:39:56Z
Mass migration of bugs marked as x86-64 to just x86. The platform run on isn't what's relevant, it's if the app is a 32 or 64 bit app.
Comment #3 by bugzilla — 2011-11-15T13:11:25Z
Actually, I think the documentation is wrong here. The C function modfl(), to which std.math.modf() forwards, does not calculate the remainder of an integer division. Rather it splits a number into an integer part and a fractional part (e.g. it splits 3.14 into 3 and 0.14).
The C function to calculate the remainder is fmod(), which doesn't seem to have a counterpart in std.math.