[Jprogramming] Puzzling result

Erling Hellenäs erling at erlinghellenas.se
Fri Sep 8 13:21:26 UTC 2017


Hi all !

It seems an IEEE double can hold this value without lost precision. I 
don't know what might happen in the calculations. Where the precision is 
lost. Maybe something with comparison tolerance.

      5729082486784839 - 5729082486784839 - 0.999

1


JWithATwist does not lose precision. Here with integer and float right 
argument.


{ ( 14 ^ 2 ) {! ] - [ * |<. ] % [  } 1.0 * 5729082486784839 }
  147
{ ( 14 ^ 2 ) {! ] - [ * |<. ] % [  } 5729082486784839 }
  147


Cheers,


Erling Hellenäs


Den 2017-09-08 kl. 13:19, skrev Erling Hellenäs:
> Case 3 seems to be working in the latest Beta(8.06.03). The problem 
> seems to be solved. /Erling
>
>      3!:0 (x: n^2)
>
> 128
>
>      (x: n^2) | 5729082486784839
>
> 147
>
>     3!:0 (x: n^2)
>
> 128
>
>
> Den 2017-09-07 kl. 20:40, skrev Erling Hellenäs:
>> Hi all !
>>
>> Case 1:
>>     3!:0 [ (n^2)
>>
>> 8
>>
>>      (n^2) | 5729082486784839
>>
>> 0
>>
>> It is non-intuitive that an integer raised to an integer is a float, 
>> but I think it is normal. It would be possible with a performance 
>> penalty to get an integer result. One problem with that is that it 
>> would easily overflow. It would also be possible to have a special 
>> operation for this case.
>> When the left argument is a float the right argument has to be 
>> converted to a float. It must be assumed that this conversion is 
>> intentional, even though it is implicit.
>>
>> Case 2:
>>      3!:0 [ (n^2)
>>
>> 8
>>
>>      (n^2) | 5729082486784839x
>>
>> 0
>>
>> 3!:0 (n^2) | 5729082486784839x
>>
>> 8
>>
>> Here the rational seems to be converted to a float and the result is 
>> float. Shouldn't we have an error instead of converting rationals to 
>> float?
>>
>> Case 3:
>>
>> 3!:0 (x: n^2)
>>
>> 128
>>
>>      (x: n^2) | 5729082486784839
>>
>> 0
>>
>> 3!:0 (x: n^2) | 5729082486784839
>>
>> 128
>>
>> I have a hard time understanding what happens here. This result seems 
>> very peculiar. Is the left and right argument converted to float and 
>> the float result converted to rational?!
>> Shouldn't we have an error instead of converting rationals to float?
>> We could not have floats auto-converted to rationals?
>> In this case the integer should be converted to rational and we 
>> should get a rational result?
>>
>> It is non-intuitive that (*: n) does not give the same result as 
>> (n^2). Maybe once this was decided because of performance reasons.
>>
>> Cheers,
>>
>> Erling Hellenäs
>>
>> On 2017-09-05 18:41, Rob B wrote:
>>> Could someone explain this please?
>>>
>>>   n=.14
>>>     n
>>> 14
>>>     (*: n) | 5729082486784839
>>> 147
>>>     196 | 5729082486784839
>>> 147
>>>     (n^2) | 5729082486784839
>>> 0
>>>     (n^2) | 5729082486784839x
>>> 0
>>>     (x: n^2) | 5729082486784839
>>> 0
>>>     (x: n^2) | 5729082486784839x
>>> 147
>>>
>>>
>>> Regards, Rob Burns
>>> ----------------------------------------------------------------------
>>> For information about J forums see http://www.jsoftware.com/forums.htm
>>
>>
>> ----------------------------------------------------------------------
>> For information about J forums see http://www.jsoftware.com/forums.htm
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm



More information about the Programming mailing list