[LLVMbugs] [Bug 611] NEW: "rem double x, y" always returns 0.0
    bugzilla-daemon at cs.uiuc.edu 
    bugzilla-daemon at cs.uiuc.edu
       
    Wed Aug  3 08:24:43 PDT 2005
    
    
  
http://llvm.cs.uiuc.edu/bugs/show_bug.cgi?id=611
           Summary: "rem double x, y" always returns 0.0
           Product: libraries
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Backend: X86
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: brukman+bugs at uiuc.edu
According to fmod(3), the remainder of dividing x by y (both FP) is "x - n * y"
where "n is the quotient of x / y, rounded towards zero to an integer.
In the x86 backend, we are not doing that rounding to an integer, but just
multiplying the result of x/y (as a floating-point value) back by y, and then
subtracing, leading to always returning 0.0 .
LLVM:
fastcc double %float_mod(double %x_2, double %y_3) {
 block0:
  ;; ** v12 = float_mod(x_2, y_3) **
  %v12 = rem double %x_2, %y_3
  br label %block1
 block1:
  %v4 = phi double [%v12, %block0]
  ret double %v4
}
X86 asm:
 float_mod:
   fldl 12(%esp)
   fldl 4(%esp)
   fld %st(0)
   fdiv %st(2)
   # MISSING rounding to integer!
   fmulp %st(2)
   fsubp %st(1)
Bug found by Eric van Riet Paap.  Thanks!
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.
    
    
More information about the llvm-bugs
mailing list