-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# HP48 GX Utilities | ||
|
||
This folder contains useful routines for the HP48 GX calculator, enhancing its native capabilities with additional functionalities. | ||
|
||
## ROUND | ||
|
||
Rounds a number to the desired number of decimal places. Place the number to be rounded on the second level of the stack and the number of desired decimal places on the first level. | ||
|
||
Example usage: | ||
``` | ||
3.14159 2 ROUND | ||
``` | ||
Results in: | ||
``` | ||
3.14 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
%%HP: T(3)A(R)F(.); | ||
|
||
\<< DUP2 \-> N R | ||
\<< | ||
DROP "" | ||
@ Check if already in SCI / ENG format or STD | ||
IF N \->STR "E" POS | ||
THEN | ||
@ SCI / ENG format | ||
@ Extract the mantissa and round it | ||
N MANT R TRNC | ||
ELSE | ||
@ STD format | ||
@ Extract the decimal part | ||
N N 0 TRNC - | ||
@ Round it - ensuring cases like N.000NN are handled | ||
DUP XPON SWAP MANT R 1 - RND SWAP 10 SWAP ^ * N 0 TRNC + MANT | ||
END | ||
@ Concatenate as string | ||
+ "E" + N XPON + | ||
@ Convert the string back to number | ||
DUP OBJ\-> | ||
\>> | ||
\>> |