QL floating point to basic conversion routine?

Anything QL Software or Programming Related.
User avatar
pjw
QL Wafer Drive
Posts: 1626
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: QL floating point to basic conversion routine?

Post by pjw »

I know no one asked for it, but as an inveterate tinkerer I felt I couldnt let an obvious logical tweak stand, er, un-tweaked, although it makes virtually no difference to the performance:

Code: Select all

rem + ------------------------------------------------------------------------ +
rem | Convert a 4 byte internal representation of a long integer into a number |
rem | No check on the length of n$, which must be four bytes exactly!          |
rem + ------------------------------------------------------------------------ +
rem | V0.02, pjw, 2024 Jul 31                                                  |
rem + ------------------------------------------------------------------------ +
:
DEFine FuNction LongInt(n$)
LOCal i%, t
t = CODE(n$(1))
FOR i% = 2 TO 4: t = t * 256 + CODE(n$(i%))
IF t = 2 ^ 32: RETurn -1: REMark Rounding "error"?
IF t > $7FFFFFFF: RETurn t - 2 ^ 32
RETurn t
END DEFine LongInt
:


Per
I love long walks, especially when they are taken by people who annoy me.
- Fred Allen
Post Reply