# Re: [Jprogramming] Fractional parts

```ip would be best implemented as

ip=: * * <.@|```
```
as it would return an integer result.

Louis

> On 06 Aug 2017, at 12:17, Skip Cave <s...@caveconsulting.com> wrote:
>
> All, Thanks for the help.
>
> Here's some real numbers from a problem I'm working on:
> Calculate some values from this equation:
>    v=:2%(3r19-%1 2 3 245 246 247 248)
> v
>    _2.375 _5.84615 _11.4 13.0028 13.0014 13 12.9986
> Raul's first suggestion:
>    1|v
> 0.625 0.153846 0.6 0.0027933 0.00139082 0 0.998621
> More precision, but signs are wrong on the negative numbers.
>
> Nolaig's suggestion:
>     (- <.) v
> 0.625 0.153846 0.6 0.0027933 0.00139082 1.77636e_15 0.998621
> Negative signs are still wrong, and the 6th entry should be zero. Looks
> like a compare tolerance problem.
>
> Pascal's solution:
>
>   1 (| |)v
>
> 0.375 0.846154 0.4 0.0027933 0.00139082 0 0.998621
> Still has the negatives wrong.
>
> Martin's solution:
> fp=.**1||
>
>   fp v
>
> _0.375 _0.846154 _0.4 0.0027933 0.00139082 0 0.998621
> Negatives are right, zeroes are right. This fractional part verb needs to
> be in the documentation as part of the numbers chapter.
>
> Also the integer part verb: ip=.]-**1||    should be included in the
> numbers section as well.
>   ip v
>
> _2 _5 _11 13 13 13 12
>
> Skip
>
> Skip Cave
> Cave Consulting LLC
>
> On Sun, Aug 6, 2017 at 6:42 AM, Raul Miller <rauldmil...@gmail.com> wrote:
>
>> 1&| does work, actually.
>>
>> And, if you want an offset of -1 on that result when the original
>> value was negative, you can use (1&| - 0&>)
>>
>> Thanks,
>>
>> --
>> Raul
>>
>> On Sun, Aug 6, 2017 at 3:19 AM, Martin Kreuzer <i...@airkreuzer.com>
>> wrote:
>>> In easy steps (and for further reference) ...
>>>
>>> From these test data (two floats, two integers, different signs), to get
>> the
>>> fractional parts
>>>
>>>   v=. 2.25 _8.11 16 _3
>>>
>>> simply taking the Residue (when dividing by 1) doesn't work (error at
>>> negative float position)
>>>
>>>   1|v
>>> 0.25 0.89 0 0
>>>
>>> So first get Magnitude
>>>
>>>   | v
>>> 2.25 8.11 16 3
>>>
>>> then take Residue
>>>
>>>   1 | (| v)
>>> 0.25 0.11 0 0
>>>
>>> then get the sign right (see Raul's remark below)
>>>
>>>   (*v) * (1 | | v)
>>> 0.25 _0.11 0 0
>>>
>>> and put it as verb (fp), written as a fork
>>>
>>>   fp=. * * 1||
>>>   fp v
>>> 0.25 _0.11 0 0
>>>
>>> -M
>>>
>>>
>>> At 2017-08-06 02:14, you wrote:
>>>
>>>> Eh... but that's wrong.  You can't add any integer to 0.542857 to get
>>>> _0.542857.
>>>>
>>>> If you want signed fractions, you'd need something like (*@] * (| |))
>>>>
>>>> Thanks,
>>>>
>>>> --
>>>> Raul
>>>>
>>>>
>>>> On Sat, Aug 5, 2017 at 10:01 PM, 'Pascal Jasmin' via Programming
>>>> <programm...@jsoftware.com> wrote:
>>>>> combining other answers we get the cute:
>>>>
>>>>> 1 (| |)  _0.542857 _1.1875 1.96552 2.92308 4.13043 5.7 7.82353 10.8571
>>>>> 15.5455 23.75
>>>>
>>>>
>>>>
>>>>
>>>>> ________________________________
>>>>> From: Bill <bbill....@gmail.com>
>>>>> To: "programm...@jsoftware.com" <programm...@jsoftware.com>
>>>>> Sent: Saturday, August 5, 2017 8:30 PM
>>>>> Subject: Re: [Jprogramming] Fractional parts
>>>>
>>>>
>>>>
>>>>> this also depends on what do you expect for negative numbers.
>>>>
>>>>> Sent from my iPhone
>>>>
>>>>> On 6 Aug, 2017, at 7:35 AM, Skip Cave <s...@caveconsulting.com>
>> wrote:
>>>>
>>>>>> Oops! i meant:
>>>>>>
>>>>>> How does one find the fractional parts of a vector of floating point
>>>>>> numbers?
>>>>>>
>>>>>> 0.542857 1.1875 1.96552 2.92308 4.13043 5.7 7.82353 10.8571 15.5455
>>>>>> 23.75
>>>>>> 41.8 114 247
>>>>>>
>>>>>> i want:
>>>>>> 0.542857 0.1875 0.96552 0.92308 0.13043 0.7 0.82353 0.8571 5.5455
>> 0.75
>>>>>> 0.8
>>>>>> 0 0
>>>>>>
>>>>>> (Last two integers have zero fractional part.)
>>>>>>
>>>>>>
>>>>>> Skip Cave
>>>>>> Cave Consulting LLC
>>>>>>
>>>>>> On Sat, Aug 5, 2017 at 6:30 PM, Skip Cave <s...@caveconsulting.com>
>>>>>> wrote:
>>>>>>
>>>>>>> How does one find the fractional parts of a vector of floating point
>>>>>>> numbers?
>>>>>>>
>>>>>>> 0.542857 1.1875 1.96552 2.92308 4.13043 5.7 7.82353 10.8571 15.5455
>>>>>>> 23.75
>>>>>>> 41.8 114 247
>>>>>>>
>>>>>>> i want:
>>>>>>> 0.542857 0.1875 0.96552 0.92308 0.13043 0.7 0.82353 0.8571 5.5455
>> 0.75
>>>>>>> 0.8
>>>>>>> 114 247
>>>>>>>
>>>>>>> Skip
>>>>>>>
>>>>>>> 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```