EDK2 doxygen online documents - Firmware Encoding Index 1
EDK2 doxygen online documents - Firmware Encoding Index

StdLib/LibC/gdtoa/strtof.c

Go to the documentation of this file.
00001 /* $NetBSD: strtof.c,v 1.2.14.1 2008/04/08 21:10:55 jdc Exp $ */
00002 
00003 /****************************************************************
00004 
00005 The author of this software is David M. Gay.
00006 
00007 Copyright (C) 1998, 2000 by Lucent Technologies
00008 All Rights Reserved
00009 
00010 Permission to use, copy, modify, and distribute this software and
00011 its documentation for any purpose and without fee is hereby
00012 granted, provided that the above copyright notice appear in all
00013 copies and that both that the copyright notice and this
00014 permission notice and warranty disclaimer appear in supporting
00015 documentation, and that the name of Lucent or any of its entities
00016 not be used in advertising or publicity pertaining to
00017 distribution of the software without specific, written prior
00018 permission.
00019 
00020 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00021 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
00022 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
00023 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00024 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
00025 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
00026 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
00027 THIS SOFTWARE.
00028 
00029 ****************************************************************/
00030 
00031 /* Please send bug reports to David M. Gay (dmg at acm dot org,
00032  * with " at " changed at "@" and " dot " changed to ".").  */
00033 #include  <LibConfig.h>
00034 
00035 #include "namespace.h"
00036 #include "gdtoaimp.h"
00037 
00038 #ifdef __weak_alias
00039 __weak_alias(strtof, _strtof)
00040 #endif
00041 
00042  float
00043 #ifdef KR_headers
00044 strtof(s, sp) CONST char *s; char **sp;
00045 #else
00046 strtof(CONST char *s, char **sp)
00047 #endif
00048 {
00049   static CONST FPI fpi = { 24, 1-127-24+1,  254-127-24+1, 1, SI };
00050   ULong bits[1];
00051   Long expt;
00052   int k;
00053   union { ULong L[1]; float f; } u = { 0 };
00054 
00055   k = strtodg(s, sp, &fpi, &expt, bits);
00056   if (k == STRTOG_NoMemory) {
00057     errno = ERANGE;
00058     return HUGE_VALF;
00059   }
00060   switch(k & STRTOG_Retmask) {
00061     case STRTOG_NoNumber:
00062     case STRTOG_Zero:
00063     u.L[0] = 0;
00064     break;
00065 
00066     case STRTOG_Normal:
00067     case STRTOG_NaNbits:
00068     u.L[0] = (bits[0] & 0x7fffff) | ((expt + 0x7f + 23) << 23);
00069     break;
00070 
00071     case STRTOG_Denormal:
00072     u.L[0] = bits[0];
00073     break;
00074 
00075     case STRTOG_Infinite:
00076     u.L[0] = 0x7f800000;
00077     break;
00078 
00079     case STRTOG_NaN:
00080     u.L[0] = f_QNAN;
00081     }
00082   if (k & STRTOG_Neg)
00083     u.L[0] |= 0x80000000L;
00084   return u.f;
00085   }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Defines