Re: My scripting language - any suggestions?

"Aleksey Demakov" <ademakov@gmail.com>
Tue, 2 Sep 2008 00:54:12 +0700

          From comp.compilers

Related articles
[4 earlier articles]
Re: My scripting language - any suggestions? jaluber@gmail.com (Johannes) (2008-08-30)
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-08-31)
Re: My scripting language - any suggestions? ademakov@gmail.com (Aleksey Demakov) (2008-08-31)
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-08-31)
Re: My scripting language - any suggestions? licaner@gmail.com (lican) (2008-08-31)
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-09-01)
Re: My scripting language - any suggestions? ademakov@gmail.com (Aleksey Demakov) (2008-09-02)
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-09-02)
Re: My scripting language - any suggestions? licaner@gmail.com (lican) (2008-09-04)
Re: My scripting language - any suggestions? jaluber@gmail.com (Johannes) (2008-09-06)
Re: My scripting language - any suggestions? ademakov@gmail.com (Aleksey Demakov) (2008-09-07)
Re: My scripting language - any suggestions? bobduff@shell01.TheWorld.com (Robert A Duff) (2008-09-07)
Re: My scripting language - any suggestions? mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2008-09-08)
[2 later articles]
| List of all articles for this month |
From: "Aleksey Demakov" <ademakov@gmail.com>
Newsgroups: comp.compilers
Date: Tue, 2 Sep 2008 00:54:12 +0700
Organization: Compilers Central
References: 08-08-069 08-08-081 08-08-100 08-08-106 08-08-107 08-08-109
Keywords: OOP, types
Posted-Date: 01 Sep 2008 17:32:57 EDT

On Sun, Aug 31, 2008 at 9:58 PM, Dmitry A. Kazakov
<mailbox@dmitry-kazakov.de> wrote:
>> If you use hardware-supported 32-bit representation of floats then
>> there will be a problem with precision. Some Int values cannot not be
>> precisely represented as floats.
>
> That is up to inherited operations. Basically, if Integer inherits
> anything from Float it also does the property of Float being an
> interval of [real] numbers, with the consequences of. If Integer can
> do this operation better, then it should override. The third
> alternative is adding ideal values to the class in the form of NaN or
> else an exception propagation.
>


Sorry, I still don't get how the inheritance thing alone could
automagically resolve all the subtle numeric issues.


Suppose we have a method that simply returns the sum of two args:


m(a, b) { return a + b; }


I could understand what happens If both args have the same type.
For instance if ints and floats both use 32-bit representation then


m(1, 2000000000)


will quite obviously result in 2000000001


while


m(1.0, 2000000000,0)


will result in 2000000000.0 - 32-bit floats do not have enough
precision to keep the '1' in the end.


Now what will happen if one argument is int and another
is float ?


m(1, 2000000000.0)


will it be 2000000001, or 2000000000,0, or a runtime error?


In any case the user might prefer one way or another. In
the last example if the user wants to preserve the precision
then this could be done by converting float to int. On the
other hand for m(1, 1.0e15) conversion to int will not work
so it should not be done.


So do you reserve the possibility for a user to do the explicit
conversion? Or never is never and explicit conversion is always
a design problem?


Regards,
Aleksey


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.