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

Anything QL Software or Programming Related.
Post Reply
User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

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

Post 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.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

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

Post 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


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

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

Post 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.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Post Reply