bowman@reed.UUCP (Eric Bowman) (01/24/91)
I'm trying to write a function in C++ to convert between floating point
and text using the script manager. Easy enough:
void plot::DecToString(double theNum,Str255 theString)
{
extended temp;
temp = (extended) theNum;
FormatX2Str(temp,&myNumFormat,&myNumberParts,theString);
}
This works fine, except when the 68881 compiler option is on.
The problem seems clear -- 96 bits versus 80 bits for the length
of an extended.
What's not so clear is how to write this function so that it will
work with or without the 68881.
Has anyone dealt with this before? Any help would be *greatly* appreciated.
Thanks,
bobo
bowman@reed.{bitnet,UUCP,edu}
...!tektronix!reed!bowman
ftanaka@Apple.COM (Forrest Tanaka) (01/26/91)
bowman@reed.UUCP (Eric Bowman) writes: >I'm trying to write a function in C++ to convert between floating point >and text using the script manager. Easy enough: > >void plot::DecToString(double theNum,Str255 theString) >{ > extended temp; > > temp = (extended) theNum; > FormatX2Str(temp,&myNumFormat,&myNumberParts,theString); >} > >This works fine, except when the 68881 compiler option is on. > >The problem seems clear -- 96 bits versus 80 bits for the length >of an extended. Your analysis of this problem is right on the money. You can convert between 80-bit and 96-bit extended numbers by using a couple of routines declared in MPW's SANE.h header file that are called x96tox80 and x80tox96. The extended80 and extended96 types aren't equivalent to the extended type as far as the C compiler is concerned, so you have to redeclare FormatX2Str and FormatStr2X to take these types. You can do this like this: pascal FormatStatus FormatX2Str (extended80 x, const NumFormatString *myCanonical, const NumberParts *partsTable, Str255 outString) = {0x2F3C,0x8210,0xFFE8,0xA8B5}; pascal FormatStatus FormatStr2X (const Str255 source, const NumFormatString *myCanonical, const NumberParts *partsTable, extended80 *x) = {0x2F3C,0x8210,0xFFE6,0xA8B5}; Call these routines instead of the originals. To call FormatX2Str80, all you have to do is this: extended x; /* 96-bit extended number */ NumFormatString myCanonical; NumberParts partsTable; Str255 outString; result = FormatX2Str80 (x96tox80 (x), &myCanonical, &partsTable, outString); Calling FormatStr2X80 is just slightly more complicated because the extended number is passed by reference: extended x; /* 96-bit extended number */ extended80 x80; /* 80-bit extended number */ Str255 source; NumFormatString myCanonical; NumberParts partsTable; x80 = x96tox80 (x); result = FormatStr2X80 (theString, &myCanonical, &partsTable, &x80); x = x80tox96 (x80); --Forrest >bobo >bowman@reed.{bitnet,UUCP,edu} >...!tektronix!reed!bowman -- Forrest Tanaka AppleLink: TANAKA Graphics/Toolbox Developer Technical Support Internet: ftanaka@apple.com Apple Computer, Inc. Phone: 408 974-1243