modulus redux

Walter Bright newshound1 at digitalmars.com
Mon Jul 13 11:38:17 PDT 2009


Andrei Alexandrescu wrote:
> Don wrote:
>> Close, but that's technically not true in the case where abs(a/b) > 
>> long.max. (The integer doesn't have to fit into a 'long').
> 
> But if real is 79-bit long (as on Intel), the largest integer that could 
> fit without loss in 1 << 63, and that would fit in a long. Are you 
> saying r could spill into large integers that cannot be represented 
> without loss?

The definition is without regard to the size of integral types. It only 
means "integer".


>> In IEEE754, r= a % b is defined by the mathematical relation r = a  – 
>> b  * n , where n is the integer nearest the exact number a/b ; 
>> whenever abs( n  – a/b) = 0.5 , then n is even. If r == 0 , its sign 
>> is the same as a.
> 
> I take it D does not define a % b the IEEE 754 way (that's why I 
> eliminated that mention). Is that correct?

No, it is defined as fmod, which is IEEE754 %. In fact, it is quite 
literally implemented by the FPREM instruction which is the same used 
for fmod().

Hmm, I just noticed that the code generator should use FPREM1 instead to 
get IEEE conformance. Darn.

http://www.sesp.cse.clrc.ac.uk/html/SoftwareTools/vtune/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc108.htm

http://www.sesp.cse.clrc.ac.uk/html/SoftwareTools/vtune/users_guide/mergedProjects/analyzer_ec/mergedProjects/reference_olh/mergedProjects/instructions/instruct32_hh/vc109.htm



More information about the Digitalmars-d mailing list