[Cuis-dev] Negative sqrt
Juan Vuletich
juan at jvuletich.org
Tue Dec 29 10:47:43 PST 2020
Hi Gerald,
(below)
On 12/29/2020 8:18 AM, Gerald Klix via Cuis-dev wrote:
>
>
> On 2020-12-29 11:59, Gerald Klix via Cuis-dev wrote:
>> On 2020-12-29 05:15, ken.dickey at whidbey.com wrote:
>>> On 2020-12-28 10:46, Juan Vuletich via Cuis-dev wrote:
>>>
>>>> Ok. Making the existence of the Complex package easier to discover is
>>>> a good idea. Just pushed an update, in the #defaultAction of
>>>> NegativePowerError. Please take a look.
>>>
>>> Looks great to me.
>>>
>>> Thanks a bunch!
>>> -KenD
>>
>> Sorry to report some strange behavior:
>> Sometimes the debugger window appears alongside the menu. Sometimes
>> it does not, answering a NaN, if you click outside the menu or choose
>> not to install the Complex package. Until now I could not find any
>> pattern.
>>
>> I will test it with a clean image, soon.
>>
>>
>> HTH,
>>
>> Gerald
> Retested with a clean 4503 release image,
> which I created from a clean copy of a 4426 image, installing all
> updates and saving it as a new release:
>
> '-4 sqrt' displays the menu and If I choose not to load the Complex
> package it pops up a debugger. If I choose proceed in the debugger,
> it answers an instance of the NegativePowerError
> exception.
>
> Choosing the same menu option with '-4.0 sqrt' directly answers a NaN.
>
> Juan, I presume that is not the behavior you intended. Please tell me,
> if I should test with a 32-bit image, that only has boxed floats.
>
>
> HTH,
>
> Gerald
Note that if you haven't selected "Install Complex" or "Don't ask
again", `-4.0 sqrt` will still ask the question, the same as if the
receiver was an integer.
The difference is if you chose not to install Complex. And, yes, it is
the intended behavior.
If Complex is installed, -4 sqrt and -4.0 sqrt answer Complex. But if
not, -4 sqrt is an error, but -4.0 sqrt isNaN. This is because of the
Floating Point standard.
Floats play by their own rules, stated in the IEEE 754 standard. They
include special values Float infinity (so 1.0 / 0.0 = Float infinity)
and Float nan (so -4.0 sqrt isNaN). The other Number classes don't
handle these concepts, and just give errors.
Strict compliance of IEEE 754 is important. Most well known numeric
algorithms are guaranteed to give the expected results if the standard
is followed, and might break otherwise.
Thanks,
--
Juan Vuletich
www.cuis-smalltalk.org
https://github.com/Cuis-Smalltalk/Cuis-Smalltalk-Dev
https://github.com/jvuletich
https://www.linkedin.com/in/juan-vuletich-75611b3
@JuanVuletich
More information about the Cuis-dev
mailing list