IP() on negative number - issue
11-28-2017, 09:58 PM (This post was last modified: 11-28-2017 09:59 PM by primer.)
Post: #1
 primer Member Posts: 135 Joined: Sep 2015
IP() on negative number - issue
Hello,
I found there is an issue with IP() function (both in home and CAS).
IP() stands for "Integer Part", ok...
but the "integer part" function is defined in math in that way :
It's the function that take a real number and return an integer n with n ≤ x < n+1.

IP(-1.5) returns -1 while the "integer part of -1.5" is -2 according to definition.
so IP() is wrong on negative numbers.

I know FLOOR() does the job, but it's a question of vocabulary.
it's confusing for math users/students.
IP() should return the same as FLOOR().
if you want a function that return -1 here you should use TRUNCATE(-1.5 ,0), not IP(-1.5)

primer
11-28-2017, 10:12 PM (This post was last modified: 11-28-2017 10:16 PM by salvomic.)
Post: #2
 salvomic Senior Member Posts: 1,364 Joined: Jan 2015
RE: IP() on negative number - issue
hi,
see here in Wolfram Alpha for definition.
IntegerPart[-1.5] returns -1 (see here).
Also in HP15C: Int(-1.5) I get -1
In HP 50g: IP(-1.5) -> -1 also...

Salvo

∫aL√0mic (IT9CLU), HP Prime 50g 41CX 71b 42s 12C 15C - DM42 WP34s :: Prime Soft. Lib
11-28-2017, 10:42 PM
Post: #3
 toml_12953 Senior Member Posts: 935 Joined: Dec 2013
RE: IP() on negative number - issue
(11-28-2017 09:58 PM)primer Wrote:  Hello,
I found there is an issue with IP() function (both in home and CAS).
IP() stands for "Integer Part", ok...
but the "integer part" function is defined in math in that way :
It's the function that take a real number and return an integer n with n ≤ x < n+1.

IP(-1.5) returns -1 while the "integer part of -1.5" is -2 according to definition.
so IP() is wrong on negative numbers.

I know FLOOR() does the job, but it's a question of vocabulary.
it's confusing for math users/students.
IP() should return the same as FLOOR().
if you want a function that return -1 here you should use TRUNCATE(-1.5 ,0), not IP(-1.5)

No, IP returns the integer part only. It just lops off any decimal. Think of it as CEIL instead of FLOOR.

Tom L

Ducator meus nihil agit sine lagunculae leynidae accedunt
11-29-2017, 05:57 AM
Post: #4
 cyrille de brébisson Senior Member Posts: 795 Joined: Dec 2013
RE: IP() on negative number - issue
Hello,

IP and FP are NOT math functions, they are programming functions. And they do work as intended, cuttting off what is on the right or left of the decimal point.

FLOOR and CEIL are math functions and do respect the rule that you stated.

This is why they are 3 (FP excluded) functions to deal with this and not two.

Cheers,
Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)