strtof.c revision 1.1
11.1Skleink/* $NetBSD: strtof.c,v 1.1 2006/01/25 15:18:53 kleink Exp $ */ 21.1Skleink 31.1Skleink/**************************************************************** 41.1Skleink 51.1SkleinkThe author of this software is David M. Gay. 61.1Skleink 71.1SkleinkCopyright (C) 1998, 2000 by Lucent Technologies 81.1SkleinkAll Rights Reserved 91.1Skleink 101.1SkleinkPermission to use, copy, modify, and distribute this software and 111.1Skleinkits documentation for any purpose and without fee is hereby 121.1Skleinkgranted, provided that the above copyright notice appear in all 131.1Skleinkcopies and that both that the copyright notice and this 141.1Skleinkpermission notice and warranty disclaimer appear in supporting 151.1Skleinkdocumentation, and that the name of Lucent or any of its entities 161.1Skleinknot be used in advertising or publicity pertaining to 171.1Skleinkdistribution of the software without specific, written prior 181.1Skleinkpermission. 191.1Skleink 201.1SkleinkLUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 211.1SkleinkINCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. 221.1SkleinkIN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY 231.1SkleinkSPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 241.1SkleinkWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER 251.1SkleinkIN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 261.1SkleinkARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF 271.1SkleinkTHIS SOFTWARE. 281.1Skleink 291.1Skleink****************************************************************/ 301.1Skleink 311.1Skleink/* Please send bug reports to David M. Gay (dmg at acm dot org, 321.1Skleink * with " at " changed at "@" and " dot " changed to "."). */ 331.1Skleink 341.1Skleink#include "gdtoaimp.h" 351.1Skleink 361.1Skleink float 371.1Skleink#ifdef KR_headers 381.1Skleinkstrtof(s, sp) CONST char *s; char **sp; 391.1Skleink#else 401.1Skleinkstrtof(CONST char *s, char **sp) 411.1Skleink#endif 421.1Skleink{ 431.1Skleink static FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, SI }; 441.1Skleink ULong bits[1]; 451.1Skleink Long exp; 461.1Skleink int k; 471.1Skleink union { ULong L[1]; float f; } u; 481.1Skleink 491.1Skleink k = strtodg(s, sp, &fpi, &exp, bits); 501.1Skleink switch(k & STRTOG_Retmask) { 511.1Skleink case STRTOG_NoNumber: 521.1Skleink case STRTOG_Zero: 531.1Skleink u.L[0] = 0; 541.1Skleink break; 551.1Skleink 561.1Skleink case STRTOG_Normal: 571.1Skleink case STRTOG_NaNbits: 581.1Skleink u.L[0] = bits[0] & 0x7fffff | exp + 0x7f + 23 << 23; 591.1Skleink break; 601.1Skleink 611.1Skleink case STRTOG_Denormal: 621.1Skleink u.L[0] = bits[0]; 631.1Skleink break; 641.1Skleink 651.1Skleink case STRTOG_Infinite: 661.1Skleink u.L[0] = 0x7f800000; 671.1Skleink break; 681.1Skleink 691.1Skleink case STRTOG_NaN: 701.1Skleink u.L[0] = f_QNAN; 711.1Skleink } 721.1Skleink if (k & STRTOG_Neg) 731.1Skleink u.L[0] |= 0x80000000L; 741.1Skleink return u.f; 751.1Skleink } 76