1*e0ac190eSjoerg /* $NetBSD: strtof_vaxf.c,v 1.8 2013/05/17 12:55:57 joerg Exp $ */
2bc89c06cSkleink
3bc89c06cSkleink /****************************************************************
4bc89c06cSkleink
5bc89c06cSkleink The author of this software is David M. Gay.
6bc89c06cSkleink
7bc89c06cSkleink Copyright (C) 1998, 2000 by Lucent Technologies
8bc89c06cSkleink All Rights Reserved
9bc89c06cSkleink
10bc89c06cSkleink Permission to use, copy, modify, and distribute this software and
11bc89c06cSkleink its documentation for any purpose and without fee is hereby
12bc89c06cSkleink granted, provided that the above copyright notice appear in all
13bc89c06cSkleink copies and that both that the copyright notice and this
14bc89c06cSkleink permission notice and warranty disclaimer appear in supporting
15bc89c06cSkleink documentation, and that the name of Lucent or any of its entities
16bc89c06cSkleink not be used in advertising or publicity pertaining to
17bc89c06cSkleink distribution of the software without specific, written prior
18bc89c06cSkleink permission.
19bc89c06cSkleink
20bc89c06cSkleink LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
21bc89c06cSkleink INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
22bc89c06cSkleink IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
23bc89c06cSkleink SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
24bc89c06cSkleink WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
25bc89c06cSkleink IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
26bc89c06cSkleink ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
27bc89c06cSkleink THIS SOFTWARE.
28bc89c06cSkleink
29bc89c06cSkleink ****************************************************************/
30bc89c06cSkleink
31bc89c06cSkleink /* Please send bug reports to David M. Gay (dmg at acm dot org,
32bc89c06cSkleink * with " at " changed at "@" and " dot " changed to "."). */
33bc89c06cSkleink
34bc89c06cSkleink /* Adapted to VAX F_floating by Klaus Klein <kleink@netbsd.org>. */
35bc89c06cSkleink
36bc89c06cSkleink #include "namespace.h"
37bc89c06cSkleink #include "gdtoaimp.h"
38c99aac45Sjoerg #include <locale.h>
39c99aac45Sjoerg #include "setlocale_local.h"
40bc89c06cSkleink
41bc89c06cSkleink #ifdef __weak_alias
__weak_alias(strtof,_strtof)4233dca3baShe __weak_alias(strtof, _strtof)
43c99aac45Sjoerg __weak_alias(strtof_l, _strtof_l)
44bc89c06cSkleink #endif
45bc89c06cSkleink
46c99aac45Sjoerg static float
47c99aac45Sjoerg _int_strtof_l(CONST char *s, char **sp, locale_t loc)
48bc89c06cSkleink {
49bc89c06cSkleink static CONST FPI fpi = { 24, 1-128-1-24+1, 255-128-1-24+1, 1, SI };
50bc89c06cSkleink ULong bits[1];
51bc89c06cSkleink Long expt;
52bc89c06cSkleink int k;
53bc89c06cSkleink union { ULong L[1]; float f; } u;
54bc89c06cSkleink
55c99aac45Sjoerg k = strtodg(s, sp, &fpi, &expt, bits, loc);
56ab625449Schristos if (k == STRTOG_NoMemory) {
57ab625449Schristos errno = ERANGE;
58db6dfce3Smatt return HUGE_VALF;
59ab625449Schristos }
60bc89c06cSkleink switch(k & STRTOG_Retmask) {
61bc89c06cSkleink case STRTOG_NoNumber:
62bc89c06cSkleink case STRTOG_Zero:
63db6dfce3Smatt default:
64db6dfce3Smatt u.f = 0.0;
65bc89c06cSkleink break;
66bc89c06cSkleink
67bc89c06cSkleink case STRTOG_Normal:
68bc89c06cSkleink u.L[0] = ((bits[0] & 0x0000ffff) << 16) | /* FracLo */
69bc89c06cSkleink ((bits[0] & 0x007f0000) >> 16) | /* FracHi */
70bc89c06cSkleink ((expt + 128 + 1 + 23) << 7); /* Exp */
71bc89c06cSkleink break;
72bc89c06cSkleink
73bc89c06cSkleink case STRTOG_Infinite:
74db6dfce3Smatt u.f = HUGE_VALF;
75bc89c06cSkleink break;
76bc89c06cSkleink
77bc89c06cSkleink }
78bc89c06cSkleink if (k & STRTOG_Neg)
79bc89c06cSkleink u.L[0] |= 0x00008000L;
80bc89c06cSkleink return u.f;
81bc89c06cSkleink }
82c99aac45Sjoerg
83c99aac45Sjoerg float
strtof(CONST char * s,char ** sp)84c99aac45Sjoerg strtof(CONST char *s, char **sp)
85c99aac45Sjoerg {
86*e0ac190eSjoerg return _int_strtof_l(s, sp, _current_locale());
87c99aac45Sjoerg }
88c99aac45Sjoerg
89c99aac45Sjoerg float
strtof_l(CONST char * s,char ** sp,locale_t loc)90c99aac45Sjoerg strtof_l(CONST char *s, char **sp, locale_t loc)
91c99aac45Sjoerg {
92c99aac45Sjoerg return _int_strtof_l(s, sp, loc);
93c99aac45Sjoerg }
94