strtorf.c revision 112158
18870Srgrimes/**************************************************************** 250476Speter 38870SrgrimesThe author of this software is David M. Gay. 42116Sjkh 52116SjkhCopyright (C) 1998, 2000 by Lucent Technologies 68870SrgrimesAll Rights Reserved 72116Sjkh 82116SjkhPermission to use, copy, modify, and distribute this software and 98870Srgrimesits documentation for any purpose and without fee is hereby 102116Sjkhgranted, provided that the above copyright notice appear in all 112116Sjkhcopies and that both that the copyright notice and this 128870Srgrimespermission notice and warranty disclaimer appear in supporting 138870Srgrimesdocumentation, and that the name of Lucent or any of its entities 142116Sjkhnot be used in advertising or publicity pertaining to 15212518Simpdistribution of the software without specific, written prior 16131001Smarcelpermission. 17141281Sdas 18212518SimpLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 1933662SjbINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. 202116SjkhIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY 21141281SdasSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22130149SdasWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 23180581SdasIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 24251404SdasARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 25251404SdasTHIS SOFTWARE. 26251404Sdas 27251404Sdas****************************************************************/ 282116Sjkh 29174684Sdas/* Please send bug reports to 30174684Sdas David M. Gay 31174684Sdas Bell Laboratories, Room 2C-463 32181074Sdas 600 Mountain Avenue 33174684Sdas Murray Hill, NJ 07974-0636 34174684Sdas U.S.A. 35181074Sdas dmg@bell-labs.com 36174684Sdas */ 37174684Sdas 38180581Sdas#include "gdtoaimp.h" 39180581Sdas 40180581Sdas void 41180581Sdas#ifdef KR_headers 422116SjkhULtof(L, bits, exp, k) ULong *L; ULong *bits; Long exp; int k; 43119017Sgordon#else 44169807SdeischenULtof(ULong *L, ULong *bits, Long exp, int k) 45181064Sdas#endif 4693211Sbde{ 4793211Sbde switch(k & STRTOG_Retmask) { 482116Sjkh case STRTOG_NoNumber: 492116Sjkh case STRTOG_Zero: 502116Sjkh *L = 0; 512116Sjkh break; 52216211Sdas 53216211Sdas case STRTOG_Normal: 542116Sjkh case STRTOG_NaNbits: 55130149Sdas L[0] = bits[0] & 0x7fffff | exp + 0x7f + 23 << 23; 56255294Stheraven break; 57226597Sdas 58141280Sdas case STRTOG_Denormal: 59181074Sdas L[0] = bits[0]; 60176243Sbde break; 61174617Sdas 62174617Sdas case STRTOG_Infinite: 63144650Sdas L[0] = 0x7f800000; 64144650Sdas break; 65176243Sbde 66140609Sdas case STRTOG_NaN: 67131320Sdas L[0] = 0x7fffffff; 68143222Sdas } 69144772Sdas if (k & STRTOG_Neg) 70140088Sdas L[0] |= 0x80000000L; 71144772Sdas } 72174684Sdas 73144091Sdas int 74257818Skargl#ifdef KR_headers 75132382Sdasstrtorf(s, sp, rounding, f) CONST char *s; char **sp; int rounding; float *f; 76176243Sbde#else 77176388Sdasstrtorf(CONST char *s, char **sp, int rounding, float *f) 78141280Sdas#endif 792116Sjkh{ 80121497Sdes static FPI fpi0 = { 24, 1-127-24+1, 254-127-24+1, 1, SI }; 81121497Sdes FPI *fpi, fpi1; 82211934Snwhitehorn ULong bits[1]; 83211934Snwhitehorn Long exp; 84211934Snwhitehorn int k; 85211934Snwhitehorn 86211934Snwhitehorn fpi = &fpi0; 87176361Sdas if (rounding != FPI_Round_near) { 88211934Snwhitehorn fpi1 = fpi0; 89157196Sdeischen fpi1.rounding = rounding; 90121497Sdes fpi = &fpi1; 91157196Sdeischen } 92157196Sdeischen k = strtodg(s, sp, fpi, &exp, bits); 93157196Sdeischen ULtof((ULong*)f, bits, exp, k); 94121497Sdes return k; 95175309Sdas } 96143222Sdas