Closed Bug 5301 Opened 25 years ago Closed 25 years ago

Errors in Math.round();

Categories

(Core :: JavaScript Engine, defect, P3)

Other
Linux
defect

Tracking

()

VERIFIED FIXED

People

(Reporter: rginda, Assigned: mike+mozilla)

Details

With js-1.4-2: js> Math.round(1.0001); 1.0000004768371582 js> rginda@ix.netcom.com
norris can you look at this or reassign to someone? it's happening on linux but not on other NT, solaris, IRIX.
I think the error is introduced on linux by the use of double fd_copysign(double x, double y) { __HI(x) = (__HI(x)&0x7fffffff)|(__HI(y)&0x80000000); return x; } from fdlibm/s_copysign.c That should be double fd_copysignLinux (double x, double y) { __LO(x) = (__LO(x) & 0xFFFFFF7F) | (__LO(y) & 0x80) return x; } on a linux platform (or probably on a x86 linux platform)
Assignee: norris → mccabe
Mike, can you try out Martin's suggested fix?
(Added Martin Honnen to the CC list.) Sure enough, the fix works. Thanks! I'd rather understand a little more about what's going on before I apply it. It would be better to fix fdlibm to be more xp than to apply a patch that applies only to linux. __LO and __HI are defined in fdlibm.h, along with __LITTLE_ENDIAN. Is the configuration stuff in fdlibm.h broken for linux? Does this effect other OSes? Is there something we can fix in fdlibm.h? Mike
Hm. Removing the patch and changing extern double fd_copysign __P((double, double)); to #define fd_copysign copysign in jslibmath.h also seems to fix the problem. But I still wonder if we weren't using fd_copysign for Linux for other reasons... I'll check in this fix if I get a chance to run some regression tests. Mike
Status: NEW → ASSIGNED
I ran the javascript regression tests, and it looks like life is better in many ways if we use the system copy sign rather than fd_copysign from fdlibm for Linux. Hm. I'd have thought fd_copysign should work for all platforms... maybe something is wrong about how we define ENDIAN for linux? I have the fix to jslibmath.h in my tree, and will check in when the tree opens.
Target Milestone: M6
I have a fix for this one; waiting for the tree to open for m6.
Status: ASSIGNED → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
Just checked in a fix to jslibmath.h to use the system copysign instead fd_copysign for linux. Thanks for spotting this.
Changing component to "Javascript Engine". "Javascript" component is being retired.
Status: RESOLVED → REOPENED
mike, did this get checked into the tip only? the branch is still broken, though it's working on the tip
Status: REOPENED → RESOLVED
Closed: 25 years ago25 years ago
Whoops, looks like I forgot it. Propagated the change (to jslibmath.h on the tip, 05/04/99 00:12, v. 3.3.) to SpiderMonkey140_BRANCH. Also cc'ing mang@subcarrier.org.
Status: RESOLVED → VERIFIED
thanks!
You need to log in before you can comment on or make changes to this bug.