Skip to content

Commit

Permalink
added utils/ROUND function
Browse files Browse the repository at this point in the history
  • Loading branch information
azimonti committed Apr 27, 2024
1 parent d829cad commit 982fa46
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
Empty file modified obj_encode_decode/enc_dec.py
100755 → 100644
Empty file.
Empty file modified obj_encode_decode/mod_enc_dec.py
100755 → 100644
Empty file.
16 changes: 16 additions & 0 deletions utils/README.md
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
```
24 changes: 24 additions & 0 deletions utils/ROUND
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\->
\>>
\>>

0 comments on commit 982fa46

Please sign in to comment.