11.7Sjoerg/* $NetBSD: strtof.c,v 1.7 2013/05/17 12:55:57 joerg 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.6Sjoerg#include <locale.h> 381.6Sjoerg#include "setlocale_local.h" 391.6Sjoerg 401.2Skleink#ifdef __weak_alias 411.2Skleink__weak_alias(strtof, _strtof) 421.6Sjoerg__weak_alias(strtof_l, _strtof_l) 431.2Skleink#endif 441.2Skleink 451.6Sjoergstatic float 461.6Sjoerg_int_strtof_l(CONST char *s, char **sp, locale_t loc) 471.1Skleink{ 481.4Schristos static CONST FPI fpi0 = { 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.4Schristos#ifdef Honor_FLT_ROUNDS 541.4Schristos#include "gdtoa_fltrnds.h" 551.4Schristos#else 561.4Schristos#define fpi &fpi0 571.4Schristos#endif 581.1Skleink 591.6Sjoerg k = strtodg(s, sp, fpi, &expt, bits, loc); 601.3Schristos if (k == STRTOG_NoMemory) { 611.3Schristos errno = ERANGE; 621.3Schristos return HUGE_VALF; 631.3Schristos } 641.1Skleink switch(k & STRTOG_Retmask) { 651.1Skleink case STRTOG_NoNumber: 661.1Skleink case STRTOG_Zero: 671.1Skleink u.L[0] = 0; 681.1Skleink break; 691.1Skleink 701.1Skleink case STRTOG_Normal: 711.1Skleink case STRTOG_NaNbits: 721.2Skleink u.L[0] = (bits[0] & 0x7fffff) | ((expt + 0x7f + 23) << 23); 731.1Skleink break; 741.1Skleink 751.1Skleink case STRTOG_Denormal: 761.1Skleink u.L[0] = bits[0]; 771.1Skleink break; 781.1Skleink 791.1Skleink case STRTOG_Infinite: 801.1Skleink u.L[0] = 0x7f800000; 811.1Skleink break; 821.1Skleink 831.1Skleink case STRTOG_NaN: 841.1Skleink u.L[0] = f_QNAN; 851.5Smrg break; 861.5Smrg 871.5Smrg default: 881.5Smrg u.L[0] = 0; /* for gcc warning */ 891.5Smrg break; 901.1Skleink } 911.1Skleink if (k & STRTOG_Neg) 921.1Skleink u.L[0] |= 0x80000000L; 931.1Skleink return u.f; 941.1Skleink } 951.6Sjoerg 961.6Sjoergfloat 971.6Sjoergstrtof(CONST char *s, char **sp) 981.6Sjoerg{ 991.7Sjoerg return _int_strtof_l(s, sp, _current_locale()); 1001.6Sjoerg} 1011.6Sjoerg 1021.6Sjoergfloat 1031.6Sjoergstrtof_l(CONST char *s, char **sp, locale_t loc) 1041.6Sjoerg{ 1051.6Sjoerg return _int_strtof_l(s, sp, loc); 1061.6Sjoerg} 107