# Re: [Jprogramming] Fractional parts

From what I've gathered so far is, that people seem to not mind that much, when extracting the fractional part from a (negative) float, they use
```
(1&|) _8.11
0.89```
```
or

(1&#:) _8.11
0.89

or

(**1||) _8.11
_0.11

```
as long as the integer and fractional part added up produce the original float value.
```
```
Q: Would somebody care to give a (scaled down) real-world example so as to give me a chance to understand where this ip/fp extraction usually comes into play and what part of the data is used for decision-making..? Thanks.
```
-M

At 2017-08-09 05:00, you wrote:

```
```True for 32 bit integers, but for 64 bit j integers and floats are the same
size.

On Aug 8, 2017 10:48 PM, "Skip Cave" <s...@caveconsulting.com> wrote:

> Don,

> You're right. Your approach achieves the same result when re-combining the
> fractional and integer part:

> ]v=:2%(3r19-%1 2 3 245 246 247 248)

>    ]'i f'=:|:0 1#:v

> _3 _6 _12 13 13 13 12

> 0.625 0.153846 0.6 0.0027933 0.00139082 0 0.998621

> i

> _3 _6 _12 13 13 13 12

> f

> 0.625 0.153846 0.6 0.0027933 0.00139082 0 0.998621

> v = i+f

> 1 1 1 1 1 1 1

> However,

>    datatype f

> floating

>    datatype i

> floating

> Where as the original fp/ip verbs give:

>     datatype fpv

> floating

>    datatype ipv

> integer

> So either approach will work, but ip returns integers, while your approach
> returns floats in both i & f cases. The fact that I originally called the
> verb the "integer part" probably led to the initial integer solution from
> the group.

> I'm not sure what advantages either approach would have, other than a space
> savings for pure integers.

> Skip

> Skip Cave
> Cave Consulting LLC

> On Tue, Aug 8, 2017 at 8:04 PM, Don Guinn <dongu...@gmail.com> wrote:

```
> > âThere are many ways to handle the fractional part of a number, depending
```> > on the problem at hand. The real difficulty seems to be handling negative
> > numbers. I like this, which rounds down negative numbers. But others
> might
> > want a different way.
> >
> >    ]'i f'=:|:0 1#:1.2 3.7 _2.1
> >   1   3  _3
> > 0.2 0.7 0.9
> >    i
> > 1 3 _3
> >
> >    f
> > 0.2 0.7 0.9
> >    i+f
> > 1.2 3.7 _2.1â
> >
> > On Tue, Aug 8, 2017 at 3:56 PM, Skip Cave <s...@caveconsulting.com>
> wrote:
> >
> > > The purpose of the "negative fractional part" is to satisfy the
> identity
> > > condition when the two parts are added back together:
> > >
> > >    ]v=:2%(3r19-%1 2 3 245 246 247 248)  NB. Create some long fractional
> > > parts.
> > >
> > > _2.375 _5.84615 _11.4 13.0028 13.0014 13 12.9986
> > >
> > >
> > > fp=. * * 1||     NB. The fractional part verb
> > >
> > > ip=: * * <.@|   NB. The integer part verb
> > >
> > >
> > > ]fpv =: fp v     NB. Save the fractional part
> > >
> > > _0.375 _0.846154 _0.4 0.0027933 0.00139082 0 0.998621
> > >
> > >
> > > ]ipv =: ip v     NB. Save the integer part
> > >
> > > _2 _5 _11 13 13 13 12
> > >
> > >
> > >
> > > ]sm =: ipv + fpv   NB. Add the two parts back together
> > >
> > > _2.375 _5.84615 _11.4 13.0028 13.0014 13 12.9986
> > >
> > >
> > >  NB. The result of adding the two parts should be identical to the
> > original
> > > vector.
> > >
> > >
> > > sm = v
> > >
> > > 1 1 1 1 1 1 1
> > >
> > > Skip Cave
> > > Cave Consulting LLC
> > >
> > > On Tue, Aug 8, 2017 at 2:14 PM, 'Bo Jacoby' via Programming <
> > > programm...@jsoftware.com> wrote:
> > >
> > > > The integer part  a  and the fractional part  b  of a number  x  is
> > such
> > > > that x=a+b and  a  is an integer and   0<:b  and  b<1 . I do know of
> no
> > > use
> > > > of a "negative fractional part".
> > > >
> > > >     Den 20:39 tirsdag den 8. august 2017 skrev Raul Miller <
> > > > rauldmil...@gmail.com>:
> > > >
> > > >
> > > >  I think we've mostly been using the wiki for live documents. (I'm
> not
> > > > sure what all would be involved in changing the phrase book.)
> > > >
> > > > Thanks,
> > > >
> > > > --
> > > > Raul
> > > >
> > > >
> > > > On Tue, Aug 8, 2017 at 2:35 PM, Skip Cave <s...@caveconsulting.com>
> > > wrote:
> > > > > It looks like we have a reliable solution to find a fractional part
> > of
> > > a
> > > > > floating point number, while maintaining the sign:
> > > > >
> > > > >    v
> > > > >
> > > > > _2.375 _5.84615 _11.4 13.0028 13.0014 13 12.9986
> > > > >
> > > > >    fp=. * * 1||    NB. Thanks to Martin
> > > > >
> > > > >    fp v
> > > > >
> > > > > _0.375 _0.846154 _0.4 0.0027933 0.00139082 0 0.998621
> > > > >
> > > > >
> > > > > Credit should also go to the people who suggested the building
> > blocks,
> > > > e.g.
> > > > >
> > > > > (1|y) Raul  --  (1||y) Pascal  --  (*y) Raul
> > > > >
> > > > > It is also nice to have the companion verb - integer part:
> > > > >
> > > > >    ip=: * * <.@|      NB. Thanks to Louis
> > > > >
> > > > >    ip v
> > > > >
> > > > > _2 _5 _11 13 13 13 12
> > > > >
> > > > >
> > > > > I have needed these functions more than once in my enginering
> work. I
> > > > > believe that these two verbs need to be inserted somewhere in the
> > > > "Numbers"
> > > > > section of the J Phrases doc. Maybe under "8A-Numbers & Counting",
> or
> > > > > 8C-Representations", or "8D-Arithmetic".
> > > > >
> > > > >
> > > > > How do we get them in the document? What section do they fit the
> best
> > > in?
> > > > > Can I edit the Phrases doc?
> > > > >
> > > > > Skip Cave
> > > > > Cave Consulting LLC
> > > > >
> > > > >
> > > > >
> > > > >>
> > > > >>
> > > > > ------------------------------------------------------------
> > ----------
> > > > > 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
> > >
> > ----------------------------------------------------------------------
> > 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```