Developer Forums relocated!

Need help with Apple Developer tools and technologies? Want to share information with other developers and Apple engineers? Visit Developer Forums at Apple.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Floating point formats: Java/C/C++, PPC and Intel platforms

Hi everyone

Where can I find out about the various bit formats used for 32 bit floating numbers in Java and C/C++ for both Mac hardware platforms?

I'm developing a Java audio application which needs to convert vast quantities of variable width integer audio samples to canonical float audio format. I've discovered that a floating point divide by the maximum integer value gives the correct answer but takes too much processor time, so I'm trying out bit-twiddling in C via JNI to carve out my own floating point bit patterns. This is very fast, however, I need to take into account the various float formats used on the different platforms so my app can be universal. Can anyone point me to the information?

Thanks in advance.

Bob

iBook G3, Mac OS X (10.4.6)

Posted on May 3, 2006 7:45 AM

Reply
Question marked as Best reply

Posted on May 5, 2006 1:57 PM

The 32 bit float formats are just byte order reversed on the two Macintosh platforms. Your just need to change the byte order as your go from Intel to PowerPC.
10 replies

May 5, 2006 11:17 PM in response to Bob Lang1

See the header file MacTypes.h. In it, you will find:

Base floating point types

Float32 32 bit IEEE float: 1 sign bit, 8 exponent bits, 23 fraction bits
Float64 64 bit IEEE float: 1 sign bit, 11 exponent bits, 52 fraction bits
Float80 80 bit MacOS float: 1 sign bit, 15 exponent bits, 1 integer bit, 63 fraction bits
Float96 96 bit 68881 float: 1 sign bit, 15 exponent bits, 16 pad bits, 1 integer bit, 63 fraction bits

May 8, 2006 6:16 AM in response to Bob Lang1

Yes,

It is IEEE format. I move binary files back and forth between PPC, Intel, SUN, SGI, IBM, COMPAQ platforms and run in all those places with C, C++ and fortran with no problems - after correctly rotating the bytes. I have not tested it with Java, but my Java programs run as fast as you would expect and that would be impossible in an emulation mode - the bit pattern must be the same. The only machines that I know of that do not use IEEE are some of the CRAY machines.

Jun 16, 2006 2:09 AM in response to James Hober

I've been writing a program in XCodes implementation of GNU C++ and judging by the accuracies of the results and stepping through the variables when it's running, it looks like all floats, doubles and long doubles are rounded to 6 digits before calculations, no matter what sizeof() the type has. With this low precision, the program I'm writing is worthless. I'd tried to #include MacTypes.h and it gave me Float96, but then gave me weird compile errors like disabling the "<<" operator for cout! Rather than hassle more with it, can you recommend where I can get a [set of] header[s] that will give me either working long doubles or, better, Float64, Float80 or Float96? Thanks and mahalos.

Blue & White G3 Mac OS X (10.4.6) Developing for 10.2.8 - 10.4.6

Jun 16, 2006 6:32 PM in response to tele_player

¡¡¡ Belay this all, and my apologies User uploaded file

I was making an error so stupid and obvious that I didn't even pick it up in more than a dozen passes:

I used the wrong value for a global constant that screwed up all the results of all my calculations. After I put in the correct value, everything calculated with beautifully accuracy. "double" and "long double" are quite sufficient for what I want.

Sorry... sometimes it takes going out on a stage in front of an audience to realize that your shirt is on backwards 😉


PS The precision of the output was never a question. I knew that to be an artifact of cout.

Blue & White G3 Mac OS X (10.4.6) Sometimes run on 10.2.8

Aug 17, 2006 10:14 AM in response to Bob Lang1

I am not sure that Rosetta floating point works the same as PPC floating point. I was using RealBasic (a PPC basic compiler) and moved one of the my compiled applications to a MacBook Pro and floating point comparisons that had been exact on the PPC stopped working under Rosetta. I changed the code to do an approximate comparison (i.e. abs(a -b) < tolerance) and this fixed things.

I reported the problem to the RealBasic people and thought nothing more of it until I fired up Adobe's InDesign and not being used to working with picas, changed the units of measurement to inches. The default letter paper size was suddenly 8.5000500050005 inches instead of the more usual 8.5! This was not a big problem, but it appears that all of InDesign's page math is running into some kind of rounding errors.

The floating point format is almost certainly IEEE, and I cannot imagine Rosetta doing anything other than using native hardware Intel floating point. On the other hand, there is a subtle difference in behavior.

I am posting this here as a follow up, but I am also going to post this as a proper question in the forum. If you have to delete one or the other of these duplicate posts, please zap the reply, not the question.

Aug 18, 2006 2:55 PM in response to Kaleberg

Hi
The default letter paper size was suddenly
8.5000500050005 inches instead of the more usual 8.5!
This was not a big problem, but it appears that all
of InDesign's page math is running into some kind of
rounding errors.


That seems odd. I'd always assumed that numbers like 0.5, 0.25, 0.125 etc were stored accurately without any rounding errors since they're represented by single bits. Looks like my assumption is wrong.

Bob

Floating point formats: Java/C/C++, PPC and Intel platforms

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.