The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

HP Prime: FLOOR, iPart , and their use in programs
Message #1 Posted by Alberto Candel on 1 Dec 2013, 12:58 p.m.

Good Morning,

The standard use for FLOOR(x) is the greatest integer less than or equal to x. I usually denote that by [x] (since Gauss), and call it "integer part." This terminology is standard in math, but not so much in comp sci.

The function iPart(x) is related to FLOOR(x) by iPart(x)=FLOOR(x) if FLOOR(x) > or = 0, and FLOOR(x)+1 otherwise. (So iPart is not the integer part, but what remains after droping everything to the right of the decimal point.) This is what the Help documentation in the Prime states, but not what it actually uses: in the Prime FLOOR(x) and iPart(x) seem to be the same thing: iPart(-1.23) returns -2, but it should return -1.

Using these function in a program brings up some serious trouble. Here is an example. This program below computes the binary expression B of a whole number N as a string of 0's and 1's:

EXPORT Bin(N)
BEGIN
LOCAL B:="";
WHILE  N>0 DO
  IF FP(N/2) =0 THEN B:=B+"0";
  ELSE B:=B+"1";
  END;
N:=FLOOR(N/2);  
END;
PRINT(B);
END;

This works fine, but if I replace the 8th line with

N:=iPart(N/2);
I get "Bin Error: Bad argument type."

The Debug feature in Program does not really help much (and is mostly undocumented in the user guide).

I hope that you can replicate this, and if so, fix it!

Edited: 1 Dec 2013, 1:22 p.m.

      
Re: HP Prime: FLOOR, iPart , and their use in programs
Message #2 Posted by Marcus von Cube, Germany on 1 Dec 2013, 1:25 p.m.,
in response to message #1 by Alberto Candel

I assume that iPart is the CAS variant of FLOOR. There are some recent discussions here about the proper use of CAS functions in programs. I guess you are looking for INT instead.

            
Re: HP Prime: FLOOR, iPart , and their use in programs
Message #3 Posted by Alberto Candel on 1 Dec 2013, 1:37 p.m.,
in response to message #2 by Marcus von Cube, Germany

I am not sure I understand. In the catalogue there is no INT, there is int but that is for integrals. Regardless, the Help for iPart is incorrect; it does not describe what iPart actually does.

[added] there is IP, problaby what you meant by INT [/added]

Edited: 1 Dec 2013, 1:40 p.m.

                  
Re: HP Prime: FLOOR, iPart , and their use in programs
Message #4 Posted by Alberto Candel on 1 Dec 2013, 1:50 p.m.,
in response to message #3 by Alberto Candel

My program works with IP. The usage of iPart and error may be related to iPart being a real number, while IP is an integer. Thanks.

                        
Re: HP Prime: FLOOR, iPart , and their use in programs
Message #5 Posted by Marcus von Cube, Germany on 1 Dec 2013, 1:52 p.m.,
in response to message #4 by Alberto Candel

INT is from the 39gII. IP and INT seem to be synonymous. The same holds for FRAC and FP.

                              
Re: HP Prime: FLOOR, iPart , and their use in programs
Message #6 Posted by Tim Wessman on 1 Dec 2013, 8:00 p.m.,
in response to message #5 by Marcus von Cube, Germany

Just a heads up - That was a mistake that will be going away very shortly.

Basically, having INT and FRAC for the integer part and fractional parts works fine *until* you have the ability to do integration. Then it gets very confusing.

Thus the commands where renamed as IP and FP to follow the 48 series naming. However, there was an entry for INT and FRAC to call the ipart/fpart command leftover in the depths of the CAS that was not noticed until after first shipping release. The next update will have that removed to avoid confusion.

TW

Edited: 1 Dec 2013, 8:34 p.m.

                                    
Re: HP Prime: FLOOR, iPart , and their use in programs
Message #7 Posted by Alberto Candel on 1 Dec 2013, 10:17 p.m.,
in response to message #6 by Tim Wessman

Also, the help for the function "exact" shows instead the function "float2rational" (which is not listed in the catalogue)


[ Return to Index | Top of Index ]

Go back to the main exhibit hall