Closed Bug 807697 Opened 13 years ago Closed 13 years ago

Enable integer to float type coercion in the Web IDL parser

Categories

(Core :: DOM: Core & HTML, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla19

People

(Reporter: ehsan.akhgari, Assigned: ehsan.akhgari)

References

(Blocks 1 open bug)

Details

Attachments

(1 file, 1 obsolete file)

The aim is to make the following work: interface Foo { void bar(optional float baz = 1); };
Attached patch Patch (v1) (obsolete) — Splinter Review
Assignee: nobody → ehsan
Status: NEW → ASSIGNED
Attachment #677450 - Flags: review?(bzbarsky)
Comment on attachment 677450 [details] [diff] [review] Patch (v1) s/intreger/integer/ and r=me
Attachment #677450 - Flags: review?(bzbarsky) → review+
Hmm. Actually, we should check that the int is exactly representable as a float and raise an error if it's not.
Attached patch Patch (v2)Splinter Review
Attachment #677450 - Attachment is obsolete: true
Attachment #677470 - Flags: review?(bzbarsky)
Comment on attachment 677470 [details] [diff] [review] Patch (v2) This should still check that the value is not too large when type is a float instead of a double, right? And it still has the comment typo. r=me with those addressed.
Attachment #677470 - Flags: review?(bzbarsky) → review+
(In reply to Boris Zbarsky (:bz) from comment #5) > This should still check that the value is not too large when type is a float > instead of a double, right? OK, I don't think I know how to do that in python. The best I can think of is to make sure that -2**24 <= intValue <= 2*24, which guarantees an exact representation for 32-bit floats. Is that good enough? If not, I need guidance on how to do the python magic to detect this case.
> Is that good enough? I think so, yes.
(In reply to Ehsan Akhgari [:ehsan] from comment #6) > (In reply to Boris Zbarsky (:bz) from comment #5) > > This should still check that the value is not too large when type is a float > > instead of a double, right? > > OK, I don't think I know how to do that in python. The best I can think of > is to make sure that -2**24 <= intValue <= 2*24, which guarantees an exact > representation for 32-bit floats. Is that good enough? If not, I need > guidance on how to do the python magic to detect this case. bz has approved the obvious cases, but if you wanted to be pedantic, this is a dirty C way of doing it: bool exactly_convertable_p(int32_t x) { if ((-1 << 24) <= x && x <= (1 << 24)) return true; int first_low_bit = __builtin_ctz(x); if (first_low_bit == 0) { return false; } return exactly_convertable_p(x >> first_low_bit); }
(In reply to Nathan Froyd (:froydnj) from comment #8) > (In reply to Ehsan Akhgari [:ehsan] from comment #6) > > (In reply to Boris Zbarsky (:bz) from comment #5) > > > This should still check that the value is not too large when type is a float > > > instead of a double, right? > > > > OK, I don't think I know how to do that in python. The best I can think of > > is to make sure that -2**24 <= intValue <= 2*24, which guarantees an exact > > representation for 32-bit floats. Is that good enough? If not, I need > > guidance on how to do the python magic to detect this case. > > bz has approved the obvious cases, but if you wanted to be pedantic, this is > a dirty C way of doing it: > > bool > exactly_convertable_p(int32_t x) > { > if ((-1 << 24) <= x && x <= (1 << 24)) > return true; > > int first_low_bit = __builtin_ctz(x); > if (first_low_bit == 0) { > return false; > } > > return exactly_convertable_p(x >> first_low_bit); > } If you rewrite this in python, and file another bug I may look into doing that, but for now all I need is to coerce 1 into 1.0. :-)
Blocks: 807533
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla19
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: