Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
strtorf.c
Go to the documentation of this file.
1 /****************************************************************
2 
3 The author of this software is David M. Gay.
4 
5 Copyright (C) 1998, 2000 by Lucent Technologies
6 All Rights Reserved
7 
8 Permission to use, copy, modify, and distribute this software and
9 its documentation for any purpose and without fee is hereby
10 granted, provided that the above copyright notice appear in all
11 copies and that both that the copyright notice and this
12 permission notice and warranty disclaimer appear in supporting
13 documentation, and that the name of Lucent or any of its entities
14 not be used in advertising or publicity pertaining to
15 distribution of the software without specific, written prior
16 permission.
17 
18 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
20 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
21 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
22 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
23 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
24 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
25 THIS SOFTWARE.
26 
27 ****************************************************************/
28 
29 /* Please send bug reports to David M. Gay (dmg at acm dot org,
30  * with " at " changed at "@" and " dot " changed to "."). */
31 
32 #include "gdtoaimp.h"
33 
34 void
35 #ifdef KR_headers
36  ULtof(L, bits, exp, k) ULong* L;
37 const ULong* bits;
38 Long exp;
39 int k;
40 #else
41 ULtof(ULong *L, const ULong *bits, Long exp, int k)
42 #endif
43 {
44  switch(k & STRTOG_Retmask)
45  {
46  case STRTOG_NoNumber:
47  case STRTOG_Zero:
48  *L = 0;
49  break;
50 
51  case STRTOG_Normal:
52  case STRTOG_NaNbits:
53  L[0] = (bits[0] & 0x7fffff) | (unsigned)((exp + 0x7f + 23) << 23);
54  break;
55 
56  case STRTOG_Denormal:
57  L[0] = bits[0];
58  break;
59 
60  case STRTOG_Infinite:
61  L[0] = 0x7f800000;
62  break;
63 
64  case STRTOG_NaN:
65  L[0] = f_QNAN;
66  }
67  if(k & STRTOG_Neg)
68  {
69  {
70  L[0] |= 0x80000000L;
71  }
72  }
73 }
74 
75 int
76 #ifdef KR_headers
77  strtorf(s, sp, rounding, f) CONST char* s;
78 char** sp;
79 int rounding;
80 float* f;
81 #else
82 strtorf(CONST char *s, char **sp, int rounding, float *f)
83 #endif
84 {
85  static FPI fpi0 = {24, 1 - 127 - 24 + 1, 254 - 127 - 24 + 1, 1, SI};
86  FPI *fpi, fpi1;
87  ULong bits[1];
88  Long exp;
89  int k;
90 
91  fpi = &fpi0;
92  if(rounding != FPI_Round_near)
93  {
94  fpi1 = fpi0;
95  fpi1.rounding = rounding;
96  fpi = &fpi1;
97  }
98  k = strtodg(s, sp, fpi, &exp, bits);
99  ULtof((ULong*)f, bits, exp, k);
100  return k;
101 }
void ULtof(ULong *L, const ULong *bits, Long exp, int k)
Definition: strtorf.c:41
#define CONST
Definition: gdtoa.h:61
int strtorf(CONST char *s, char **sp, int rounding, float *f)
Definition: strtorf.c:82
#define fpi1
#define SI
Definition: gdtoaimp.h:635
unsigned Long ULong
Definition: gdtoa.h:41
Definition: gdtoa.h:86
#define Long
Definition: gdtoa.h:38
int strtodg(CONST char *s00, char **se, FPI *fpi, Long *exp, ULong *bits)
Definition: strtodg.c:443