Home | History | Annotate | Line # | Download | only in gdtoa
      1  1.6     joerg /* $NetBSD: strtopx.c,v 1.6 2013/04/18 21:54:11 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 #include "gdtoaimp.h"
     35  1.1    kleink 
     36  1.1    kleink #undef _0
     37  1.1    kleink #undef _1
     38  1.1    kleink 
     39  1.2    kleink /* one or the other of IEEE_BIG_ENDIAN or IEEE_LITTLE_ENDIAN should be #defined */
     40  1.1    kleink 
     41  1.2    kleink #ifdef IEEE_BIG_ENDIAN
     42  1.1    kleink #define _0 0
     43  1.1    kleink #define _1 1
     44  1.1    kleink #define _2 2
     45  1.1    kleink #define _3 3
     46  1.1    kleink #define _4 4
     47  1.1    kleink #endif
     48  1.2    kleink #ifdef IEEE_LITTLE_ENDIAN
     49  1.1    kleink #define _0 4
     50  1.1    kleink #define _1 3
     51  1.1    kleink #define _2 2
     52  1.1    kleink #define _3 1
     53  1.1    kleink #define _4 0
     54  1.1    kleink #endif
     55  1.1    kleink 
     56  1.1    kleink  int
     57  1.6     joerg strtopx(CONST char *s, char **sp, void *V, locale_t loc)
     58  1.1    kleink {
     59  1.5  christos 	static const FPI fpi0 = { 64, 1-16383-64+1, 32766 - 16383 - 64 + 1, 1, SI };
     60  1.1    kleink 	ULong bits[2];
     61  1.3    kleink 	Long expt;
     62  1.1    kleink 	int k;
     63  1.1    kleink 	UShort *L = (UShort*)V;
     64  1.5  christos #ifdef Honor_FLT_ROUNDS
     65  1.5  christos #include "gdtoa_fltrnds.h"
     66  1.5  christos #else
     67  1.5  christos #define fpi &fpi0
     68  1.5  christos #endif
     69  1.1    kleink 
     70  1.6     joerg 	k = strtodg(s, sp, fpi, &expt, bits, loc);
     71  1.4  christos 	if (k == STRTOG_NoMemory)
     72  1.4  christos 		return k;
     73  1.1    kleink 	switch(k & STRTOG_Retmask) {
     74  1.1    kleink 	  case STRTOG_NoNumber:
     75  1.1    kleink 	  case STRTOG_Zero:
     76  1.1    kleink 		L[0] = L[1] = L[2] = L[3] = L[4] = 0;
     77  1.1    kleink 		break;
     78  1.1    kleink 
     79  1.1    kleink 	  case STRTOG_Denormal:
     80  1.1    kleink 		L[_0] = 0;
     81  1.1    kleink 		goto normal_bits;
     82  1.1    kleink 
     83  1.1    kleink 	  case STRTOG_Normal:
     84  1.1    kleink 	  case STRTOG_NaNbits:
     85  1.3    kleink 		L[_0] = expt + 0x3fff + 63;
     86  1.1    kleink  normal_bits:
     87  1.1    kleink 		L[_4] = (UShort)bits[0];
     88  1.1    kleink 		L[_3] = (UShort)(bits[0] >> 16);
     89  1.1    kleink 		L[_2] = (UShort)bits[1];
     90  1.1    kleink 		L[_1] = (UShort)(bits[1] >> 16);
     91  1.1    kleink 		break;
     92  1.1    kleink 
     93  1.1    kleink 	  case STRTOG_Infinite:
     94  1.1    kleink 		L[_0] = 0x7fff;
     95  1.5  christos 		L[_1] = 0x8000;
     96  1.5  christos 		L[_2] = L[_3] = L[_4] = 0;
     97  1.1    kleink 		break;
     98  1.1    kleink 
     99  1.1    kleink 	  case STRTOG_NaN:
    100  1.1    kleink 		L[0] = ldus_QNAN0;
    101  1.1    kleink 		L[1] = ldus_QNAN1;
    102  1.1    kleink 		L[2] = ldus_QNAN2;
    103  1.1    kleink 		L[3] = ldus_QNAN3;
    104  1.1    kleink 		L[4] = ldus_QNAN4;
    105  1.1    kleink 	  }
    106  1.1    kleink 	if (k & STRTOG_Neg)
    107  1.1    kleink 		L[_0] |= 0x8000;
    108  1.1    kleink 	return k;
    109  1.1    kleink 	}
    110