The Museum of HP Calculators


Convert between Float and Integer, also INT, RND functions for the HP-16C

This program is by Richard Beal and is used here by permission.

This program is supplied without representation or warranty of any kind. Richard Beal and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

Overview

This program provides a way to convert any number from float to integer or integer to float. It works with any number, positive, negative or fractional. Fractions are truncated.

It also provides another two missing functions, INT removes the fractional part of a floating number, and RND which rounds a floating number to the nearest integer.

INSTRUCTIONS
GSB A to convert from Float to Integer (hex)
GSB 9 to convert from Integer to Float.
GSB B INT function, removes the fractional part of a floating number
GSB D RND function, rounds a floating number to the nearest integer

Notes: The older program currently in the library has a bug. It says that any fractional part is truncated. Instead it gives incorrect results. (Try it with a number like 1.2 if you doubt me). It also goes wrong with negative numbers.

I have rewritten it so that it works correctly. It now works correctly with fractional numbers, and also supports negative numbers. This submission is the new version which also provides the INT and RND functions that are missing from this calculator.

Listing

Step	ListKey	Mnemo	Comments
001	43,22,2	g LBL 2	Subroutine to store sign
002	43,5,2	g CF 2	
003	43 2	g x<0	
004	43,4,2	g SF 2	
005	43 8	g ABS	
006	43 21	g RTN	
007	43,22,3	g LBL 3	Subroutine to round
008	42 49	f EEX	
009	9	9	
010	40	+	
011	43 36	g LSTx	
012	30	-	
013	43 21	g RTN	
014	43,22,a	g LBL A	Float to Int
015	21 2	GSB 2	
016	23	HEX	Convert
017	43 8	g ABS	
018	44 32	STO I	
019	34	x<>y	
020	43,22,1	g LBL 1	
021	43 b	g ASR	
022	43 23	g DSZ	
023	22 1	GTO 1	
024	0	0	Set wordsize to 64
025	42 44	f WSIZE	
026	43,4,3	g SF 3	
027	43,22,4	g LBL 4	
028	43,6,2	g F? 2	Restore sign
029	49	CHS	
030	43,4,3	g SF 3	Show leading zeroes
031	43 21	g RTN	
032	43,22,b	g LBL B	INT
033	21 2	GSB 2	
034	21 3	GSB 3	
035	43 3	g x>y	Adjust rounded result by 1
036	1	1	
037	0	0	
038	36	Enter	
039	1	1	
040	0	0	
041	10	/	
042	30	-	
043	22 4	GTO 4	
044	43,22,d	g LBL D	RND
045	21 2	GSB 2	
046	21 3	GSB 3	
047	22 4	GTO 4	
048	43,22,9	g LBL 9	Int to Float
049	0	0	
050	42,45,4	f FLOAT 4	Number of decimal places
051	43 21	g RTN	

Go back to the software library
Go back to the main exhibit hall