HP Prime: FLOOR, iPart , and their use in programs



#2

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.


#3

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.


#4

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.


#5

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.


#6

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


#7

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.


#8

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Does the HP Prime really compiles the user programs? CompSystems 3 2,725 12-13-2013, 01:55 PM
Last Post: Mike Morrow
  HP Prime: Lists in programs Alberto Candel 7 3,489 12-04-2013, 02:16 AM
Last Post: Alberto Candel
  HP Prime: matrices in programs, in need of help Alberto Candel 9 3,204 11-26-2013, 01:33 AM
Last Post: cyrille de Brébisson
  HP Prime: password protection for programs Davi Ribeiro de Oliveira 2 1,574 11-22-2013, 12:45 PM
Last Post: Geoff Quickfall
  Prime: Scope of Variable and functions within programs Thomas Chrapkiewicz 9 3,270 11-18-2013, 03:39 PM
Last Post: Thomas Chrapkiewicz
  Question about transfering programs to the HP Prime Namir 10 3,420 11-17-2013, 04:01 PM
Last Post: Namir
  [Download] PrimeComm: Alternative small utility to upload/download programs to the HP Prime Erwin Ried 6 2,501 11-17-2013, 10:18 AM
Last Post: Erwin Ried
  HP Prime: do not send programs and shuts down by pressing Apps Davi Ribeiro de Oliveira 1 1,340 11-12-2013, 11:05 AM
Last Post: Joseph Ec
  Grouping programs on the HP Prime Michael de Estrada 11 3,694 11-04-2013, 01:38 PM
Last Post: Damien
  More programs for polar-rectangular conversion on HP Prime Michael de Estrada 4 1,947 11-04-2013, 12:43 AM
Last Post: Michael de Estrada

Forum Jump: