strtof.c revision 1.2
11.2Skleink/* $NetBSD: strtof.c,v 1.2 2006/03/15 17:35:18 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.2Skleink#include "namespace.h" 351.1Skleink#include "gdtoaimp.h" 361.1Skleink 371.2Skleink#ifdef __weak_alias 381.2Skleink__weak_alias(strtof, _strtof) 391.2Skleink#endif 401.2Skleink 411.1Skleink float 421.1Skleink#ifdef KR_headers 431.1Skleinkstrtof(s, sp) CONST char *s; char **sp; 441.1Skleink#else 451.1Skleinkstrtof(CONST char *s, char **sp) 461.1Skleink#endif 471.1Skleink{ 481.2Skleink static CONST FPI fpi = { 24, 1-127-24+1, 254-127-24+1, 1, SI }; 491.1Skleink ULong bits[1]; 501.2Skleink Long expt; 511.1Skleink int k; 521.1Skleink union { ULong L[1]; float f; } u; 531.1Skleink 541.2Skleink k = strtodg(s, sp, &fpi, &expt, bits); 551.1Skleink switch(k & STRTOG_Retmask) { 561.1Skleink case STRTOG_NoNumber: 571.1Skleink case STRTOG_Zero: 581.1Skleink u.L[0] = 0; 591.1Skleink break; 601.1Skleink 611.1Skleink case STRTOG_Normal: 621.1Skleink case STRTOG_NaNbits: 631.2Skleink u.L[0] = (bits[0] & 0x7fffff) | ((expt + 0x7f + 23) << 23); 641.1Skleink break; 651.1Skleink 661.1Skleink case STRTOG_Denormal: 671.1Skleink u.L[0] = bits[0]; 681.1Skleink break; 691.1Skleink 701.1Skleink case STRTOG_Infinite: 711.1Skleink u.L[0] = 0x7f800000; 721.1Skleink break; 731.1Skleink 741.1Skleink case STRTOG_NaN: 751.1Skleink u.L[0] = f_QNAN; 761.1Skleink } 771.1Skleink if (k & STRTOG_Neg) 781.1Skleink u.L[0] |= 0x80000000L; 791.1Skleink return u.f; 801.1Skleink } 81