Exactly -I agree that the NaN result is quite satisfactory .It explains the problem better than the ff verb that gives a 1. That is the reason for the "why" The ff verb does give a switch -if the result is 1 then do something else. However returning 1 is not a sure way to differentiate between a NaN and 10%10
However using
NaN'= __ %__  gives an error
so it can't be used as a switch

In the old days, an infinite or unreal result generally meant a lot of kludging of programs to avoid this. (if divisor =0 do something else).

Don
On 11/19/2015 5:07 AM, Henry Rich wrote:
Why NOT NaN? What else? _ embraces numbers of vastly different sizes. aleph-0%aleph-1 is 0, aleph-1%aleph-0 is _, and (who knows?) there could be values in between. Here NaN means 'unknown'. In other cases it means 'unrepresentable'.

The standard specifies a number of operations that generate NaN:

https://en.wikipedia.org/wiki/NaN#Operations_generating_NaN

J treats some of these, but not all, as NaNs.

Henry Rich

On 11/19/2015 1:11 AM, Don Kelly wrote:
How is this "why" ? it appears that all it does is substitute a number (in this case 1) rather than have NaN. I can see this as a way to avoid a NaN error by flagging it without stopping execution.- not as an explanation for the NaN using __%__

*ff=: % :: 9:*


__ ff __

9

    3 ff 2
1.5

also works with
*ff2=: - :: 9:*

__ ff2 __

9

4 ff2 1

3


Don

On 11/18/2015 8:28 PM, Linda A Alvord wrote:
Here's why...

    f=:0:@% ::1:
    _ f _
Linda
1

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Raul Miller
Sent: Monday, November 16, 2015 1:46 PM
To: Programming forum
Subject: Re: [Jprogramming] Why is subtraction and division of rational numbers so hard?

You might also like to see:

    L=:(-_),(-2%~1-~%:5),0,(2%~1-~%:5),_
    0:@% ::1:"0/~ L
1 0 0 0 1
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
1 0 0 0 1

Thanks,


----------------------------------------------------------------------
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

Reply via email to