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)
Tracking
()
RESOLVED
FIXED
mozilla19
People
(Reporter: ehsan.akhgari, Assigned: ehsan.akhgari)
References
(Blocks 1 open bug)
Details
Attachments
(1 file, 1 obsolete file)
1.99 KB,
patch
|
bzbarsky
:
review+
|
Details | Diff | Splinter Review |
The aim is to make the following work:
interface Foo {
void bar(optional float baz = 1);
};
Assignee | ||
Comment 1•13 years ago
|
||
![]() |
||
Comment 2•13 years ago
|
||
Comment on attachment 677450 [details] [diff] [review]
Patch (v1)
s/intreger/integer/ and r=me
Attachment #677450 -
Flags: review?(bzbarsky) → review+
![]() |
||
Comment 3•13 years ago
|
||
Hmm. Actually, we should check that the int is exactly representable as a float and raise an error if it's not.
![]() |
||
Updated•13 years ago
|
Blocks: ParisBindings
Assignee | ||
Comment 4•13 years ago
|
||
Attachment #677450 -
Attachment is obsolete: true
Attachment #677470 -
Flags: review?(bzbarsky)
![]() |
||
Comment 5•13 years ago
|
||
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+
Assignee | ||
Comment 6•13 years ago
|
||
(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.
![]() |
||
Comment 7•13 years ago
|
||
> Is that good enough?
I think so, yes.
![]() |
||
Comment 8•13 years ago
|
||
(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);
}
Assignee | ||
Comment 9•13 years ago
|
||
(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
Assignee | ||
Comment 10•13 years ago
|
||
Comment 11•13 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Flags: in-testsuite+
Resolution: --- → FIXED
Target Milestone: --- → mozilla19
Updated•7 years ago
|
Component: DOM → DOM: Core & HTML
You need to log in
before you can comment on or make changes to this bug.
Description
•