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