To see the literal structure of a floating point number, you can use:
fpdigits=:3 :'(1 j.0 11 e.~i.64)#'' ''-.~":,(8#2)#:a.i.|._8{.3!:1 y+1.1-1.1'"0
NB. sign (1 is negative), mantissa+1023, exponent with implied leading 1
Here, I'm going to use it to illustrate two issues:
a) floating point representation is not a decimal notation.
fpdigits 0.2
0 01111111100 1001100110011001100110011001100110011001100110011010
b) as Henry Rich pointed out, the zeros repeat for otherwise exact
binary fractions:
fpdigits 0.5
0 01111111110 0000000000000000000000000000000000000000000000000000
There are a few other tricks and issues related to floating point
numbers, but this should help?
Thanks,
--
Raul
On Wed, Jun 13, 2018 at 3:06 PM Skip Cave <[email protected]> wrote:
>
> Skip said:
> Given the vector a:
>
> ]a =. % 1+i.20
>
> 1 0.5 0.333333 0.25 0.2 0.166667 0.142857 0.125 0.111111 0.1 0.0909091
> 0.0833333 0.0769231 0.0714286 0.0666667 0.0625 0.0588235 0.0555556
> 0.0526316 0.05
>
> Roger said:
> Your list a are reciprocals of integers and so are all rational.
>
> Roger also said:
> All rational fractions result in infinitely repeating floating point
> numbers. They are the same sets.
>
> Skip says:
> So all the numbers in a are rational, and infinitely repeating? Like 0.5,
> 0.25. 0.2, 0.1? I'm confused. These examples don't seem to have infinitely
> repeating decimals.
>
> Skip
>
>
> On Wed, Jun 13, 2018 at 12:44 PM Roger Hui <[email protected]>
> wrote:
>
> > What's an irrational number in this context? Your list a are reciprocals
> > of integers and so are all rational. On the other hand, going just by the
> > display, 0.5 is a rational number (1%2), but since the display is to 6
> > significant digits, for all you know 0.5 could be
> > 0.500000314159265358979... (0.5+ pi*1e_7) and irrational.
> >
> >
> > On Wed, Jun 13, 2018 at 10:29 AM, Skip Cave <[email protected]>
> > wrote:
> >
> > > Here's another problem similar to my previous one about finding integers
> > in
> > > a floating point array:
> > >
> > > Find the irrational numbers in a floating-point array:
> > >
> > > Given the vector a:
> > >
> > > ]a =. % 1+i.20
> > >
> > > 1 0.5 0.333333 0.25 0.2 0.166667 0.142857 0.125 0.111111 0.1 0.0909091
> > > 0.0833333 0.0769231 0.0714286 0.0666667 0.0625 0.0588235 0.0555556
> > > 0.0526316 0.05
> > >
> > >
> > > Create a function that will generate a boolean array indicating the
> > > locations of the irrational numbers in a.
> > >
> > >
> > > Skip
> > > ----------------------------------------------------------------------
> > > 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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm