Closed Bug 118117 Opened 23 years ago Closed 21 years ago

Improper single precision constants in nsUnitConversion.h

Categories

(Core :: Layout, defect, P1)

x86
Linux
defect

Tracking

()

RESOLVED FIXED

People

(Reporter: tenthumbs, Assigned: roc)

References

Details

Attachments

(2 files, 1 obsolete file)

Look at the definitions of CEIL_CONST_FLOAT and ROUND_EXCLUSIVE_CONST_FLOAT in mozilla/xpcom/ds/nsUnitConversion.h. The constants are too precise for single precision IEEE floating point. On Linux, gcc quietly converts them to the nearest single precision value which are 1.0 and 0.5 respectively. This breaks the functions that use these constants. The comments in the code indicate the author knew something could go wrong and it has. On Linux, it should really be something like #define CEIL_CONST_FLOAT (1.0f - FLT_EPSILON) #define ROUND_EXCLUSIVE_CONST_FLOAT (0.5f*CEIL_CONST_FLOAT) That should probably work for ANSI compilers but I'm sure there's some exception out there. Because this affects all sorts of things, I'm setting the severity to critical.
We're subtracting, not adding, so it should be #define CEIL_CONST_FLOAT (1.0f - 0.5f*FLT_EPSILON)
blames to peterl. not sure if he actually added these constants.
Assignee: dougt → peterl
Blocks: 120690
These belong to the peterl before me, --->back to XPCOM Note: I'm "peterlubczynski" in CVS.
Assignee: peterl → dougt
Over to LAYOUT. This header does not belong in XPCOM.
Assignee: dougt → attinasi
Component: XPCOM → Layout
QA Contact: scc → petersen
Target Milestone: --- → mozilla1.1
Blocks: 134942
tenthumbs, if you have a proposed for this bug, can you attach a patch? Thanks.
SInce I can't test all compilers I can't provide a patch. However, for gcc on Linux (and presumably other gcc's) you change the two defines taht are marked as suspect to something like this: #define CEIL_CONST_FLOAT (1.0f - 0.5*FLT_EPSILON) #define ROUND_EXCLUSIVE_CONST_FLOAT (0.5f*CEIL_CONST_FLOAT) This should work on most reasonable compilers but that's not saying much. You should also check that the compiler pre-computes these. Calculating these at run time is a performance loss.
->Misc Code
Assignee: attinasi → other
QA Contact: petersen → ian
->Misc Code
Assignee: other → misc
Component: Layout → Layout: Misc Code
QA Contact: ian → nobody
retargeting
Target Milestone: mozilla1.1alpha → Future
Target Milestone: Future → ---
Attached patch PatchSplinter Review
Comment on attachment 135586 [details] [diff] [review] Patch Thoughts?
Attachment #135586 - Flags: superreview?(roc)
Attachment #135586 - Flags: review?(roc)
Comment on attachment 135586 [details] [diff] [review] Patch Looks reasonable. I think any need for these constants indicates a design flaw...
Attachment #135586 - Flags: superreview?(roc)
Attachment #135586 - Flags: superreview+
Attachment #135586 - Flags: review?(roc)
Attachment #135586 - Flags: review+
.
Assignee: misc → bz-vacation
Checked in.
Status: NEW → RESOLVED
Closed: 21 years ago
Resolution: --- → FIXED
Reality has kept me away from mozilla for the last few weeks so I'm way behind in bugs. Sorry for the late response. Unfortunately, the patch is not correct. Presumably CEIL_CONST_FLOAT is supposed to be less than but as close to 1.0 as possible. FLT_EPSILON is the smallest number that can be _added_ to 1.0. Subtraction is different, which I said in comment 2. I have a demo if anyone doesn't believe me (and they shouldn't). Reopening with a patch upcoming.
Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Attached patch simple fix patch (obsolete) — Splinter Review
.
Assignee: bz-vacation → tenthumbs
Status: REOPENED → NEW
Attached patch the right fixSplinter Review
Assigning bugs to me is a sure way top make them disappear, but .... This should do it. Use a real value for FLT_EPSILON not a made-up one jsut in case. I could be convinced that it might be better to error out if FLT_EPSILON isn't defined.
Attachment #136012 - Attachment is obsolete: true
Attachment #137751 - Flags: superreview?(bz-vacation)
Attachment #137751 - Flags: review?(roc)
Oh yeah, someone will have to check this in for me.
Comment on attachment 137751 [details] [diff] [review] the right fix sr=bzbarsky (I also can't check this in, so someone else would need to do it).
Attachment #137751 - Flags: superreview?(bz-vacation) → superreview+
Comment on attachment 137751 [details] [diff] [review] the right fix I'll check in
Attachment #137751 - Flags: review?(roc) → review+
Assigning to myself for checkin
Assignee: tenthumbs → roc
Priority: -- → P1
Fix checked in.
Status: NEW → RESOLVED
Closed: 21 years ago21 years ago
Resolution: --- → FIXED
*** Bug 120690 has been marked as a duplicate of this bug. ***
Product: Core → Core Graveyard
Component: Layout: Misc Code → Layout
Product: Core Graveyard → Core
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: