Page 1 of 1

QL Float format to C68 float format - sort of...

Posted: Mon Aug 26, 2019 8:27 pm
by NormanDunbar
Evening All,

I'm writing a utility - it's a long term project of mine - in C68. For testing I'm using both xtcc on Linux, and compiling the code with gcc as well. I'm needing some code to convert a QL 6 byte floating point to a "normal" floating point both in C68 (native to the QL) and also for a float variable under gcc - purely for testing.

I'm assuming that floats under C68 are normal QL floats and will not need converting - I seem to remember this, but I might be wrong, but the "standard" float on Linux under gcc is way different. Can anyone point me at/supply a chunk of code to do the conversion please?

Much obliged. And, one day, If I ever finish this, you'll all be the first to know! ;)


Cheers,
Norm.

Re: QL Float format to C68 float format - sort of...

Posted: Mon Aug 26, 2019 8:52 pm
by tofro
NormanDunbar wrote:Evening All,

I'm writing a utility - it's a long term project of mine - in C68. For testing I'm using both xtcc on Linux, and compiling the code with gcc as well. I'm needing some code to convert a QL 6 byte floating point to a "normal" floating point both in C68 (native to the QL) and also for a float variable under gcc - purely for testing.

I'm assuming that floats under C68 are normal QL floats and will not need converting - I seem to remember this, but I might be wrong, but the "standard" float on Linux under gcc is way different. Can anyone point me at/supply a chunk of code to do the conversion please?

Much obliged. And, one day, If I ever finish this, you'll all be the first to know! ;)


Cheers,
Norm.
Norman,

Nope. C68 uses its own (or, rather IEEE) floating point format, different from and more precise than the QL's native format (it uses 8 bytes instead of six). C68 still can handle 6-byte QL floats, these are of type "QLFLOAT_t". That is, a Linux gcc "double" has the very same format as a C68 one.

Conversion between both formats is simple on C68:

Code: Select all

QLFLOAT_t * d_to_qlfp( QLFLOAT_t * qlf, double val)  
takes a double and converts it to a QLFLOAT_t and

Code: Select all

double qlfp_to_d (QLFLOAT_t * qlfp) 
goes the other way round.

For gcc, it's probably a bit more complicated - I'd look into the C68 library sources and port the above two routines.

Tobias

Re: QL Float format to C68 float format - sort of...

Posted: Mon Aug 26, 2019 10:13 pm
by NormanDunbar
Much obliged Tobias, thanks. I could take the lazy way out and just test on QPC, but what would be the fun in that!

I'll see what I can find in the source.


Cheers,
Norm.