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

Anything QL Software or Programming Related.
User avatar
NormanDunbar
Super Gold Card
Posts: 745
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

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

Postby NormanDunbar » Mon Aug 26, 2019 8:27 pm

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.


Why do they put lightning conductors on churches?
If at first you don't succeed, don't take up skydiving!
If you think your job is pointless, remember, there's someone in Germany who fits indicators to BMWs.
User avatar
tofro
QL Wafer Drive
Posts: 1595
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

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

Postby tofro » Mon Aug 26, 2019 8:52 pm

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


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
NormanDunbar
Super Gold Card
Posts: 745
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

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

Postby NormanDunbar » Mon Aug 26, 2019 10:13 pm

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.


Why do they put lightning conductors on churches?
If at first you don't succeed, don't take up skydiving!
If you think your job is pointless, remember, there's someone in Germany who fits indicators to BMWs.

Who is online

Users browsing this forum: No registered users and 3 guests