Revisiting Decimal

Kris Zyp kris at sitepen.com
Wed Jan 14 16:44:26 PST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
 


Brendan Eich wrote:
> On Jan 9, 2009, at 3:08 PM, Kris Zyp wrote:
>
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>>
>>> The counter-argument is strong:
>>>
>>> typeof x == typeof y => (x == y <=> x === y)
>>>
>>> but 1.1 != 1.1m for fundamental reasons.
>> I understand the counter-argument, but with such an overwhelming
>> number of typeof uses having far easier migration with "number",
>
> Migration how? You'll have to change something to "use decimal" or
> s/1.1/1.1m/. Only once you do that can you be sure about all
> operands being decimal.
>
And I am sure our users will do that and pass decimals into our
library functions.
> I'm assuming it would be "bad" in the Dojo code you've looked at if
> 1.1 came in from some standard library that returns doubles, and was
> tested against 1.1m via == or === with false result, where previous
> to decimal being added, the result would be true.
I am not aware of any situations in the Dojo codebase where this would
cause a problem. I can't think of any place where we use an
equivalence test and users would expect that decimal behave in the
same way as a double. Do you have any expected pitfalls that I could
look for in Dojo?

>
>
>> I can't possibly see how the desire to preserve this property is more
>> important than better usability for the majority use cases.
>
> You really need to show some of these use cases from Dojo. I have a
> hard time believing you've ruled out mixed-mode accidents.
Ok, sounds good, I will be glad to be corrected if I misunderstanding
this. Here are some of the places where I believe we would probably
add extra code to handle the case of typeof checks where decimal
values may have been passed in by users, and we would want the
behavior to be the same as a number:
As I have mentioned before, we would need to change our JSON
serializer to handle "decimal":
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojo/_base/json.js
(line 118)
Our parser function would need to add support for "decimal"
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojo/parser.js
(line 32)
Matrix math handling for our graphics module:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/gfx/matrix.js
(line 88 is one example)
Actually there are numerous situations in the graphics packages where
a decimal should be acceptable for defining coordinates, scaling, etc.:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/gfx/
Charting also has a number of places where decimals should be an
acceptable form of a number:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/charting/
For example:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/charting/action2d/Magnify.js
(line 22)

Again, I understand there are difficulties with typeof 1.1m returning
"number", but in practice it seems we would experience far more pain
with "decimal".

- --
Kris Zyp
SitePen
(503) 806-1841
http://sitepen.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
 
iEYEARECAAYFAkluhukACgkQ9VpNnHc4zAyaLgCeLbJeVvoLd1ypvK9uiyfO0Jhw
RuEAoKNZQeBKKfHzoupEdY+Nv16Lk+ch
=pV7U
-----END PGP SIGNATURE-----



More information about the Es-discuss mailing list