Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!apple!ftanaka From: ftanaka@Apple.COM (Forrest Tanaka) Newsgroups: comp.sys.mac.programmer Subject: Re: Script Manager 68881 woes Keywords: Script Mgr, mc68881,c++ Message-ID: <48509@apple.Apple.COM> Date: 26 Jan 91 07:20:35 GMT References: <15933@reed.UUCP> Organization: Apple Computer Inc., Cupertino, CA Lines: 75 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