os/ossrv/genericopenlibs/cppstdlib/stl/src/num_get_float.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
 * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
sl@0
     3
 *
sl@0
     4
 * Copyright (c) 1999
sl@0
     5
 * Silicon Graphics Computer Systems, Inc.
sl@0
     6
 *
sl@0
     7
 * Copyright (c) 1999
sl@0
     8
 * Boris Fomitchev
sl@0
     9
 *
sl@0
    10
 * This material is provided "as is", with absolutely no warranty expressed
sl@0
    11
 * or implied. Any use is at your own risk.
sl@0
    12
 *
sl@0
    13
 * Permission to use or copy this software for any purpose is hereby granted
sl@0
    14
 * without fee, provided the above notices are retained on all copies.
sl@0
    15
 * Permission to modify the code and to distribute modified code is granted,
sl@0
    16
 * provided the above notices are retained, and a notice that the code was
sl@0
    17
 * modified is included with the above copyright notice.
sl@0
    18
 *
sl@0
    19
 */
sl@0
    20
sl@0
    21
#include "stlport_prefix.h"
sl@0
    22
sl@0
    23
#include <limits>
sl@0
    24
#include <locale>
sl@0
    25
#include <istream>
sl@0
    26
sl@0
    27
#if defined (__GNUC__) && !defined (__sun) || \
sl@0
    28
    defined (__DMC__)
sl@0
    29
#  include <stdint.h>
sl@0
    30
#endif
sl@0
    31
sl@0
    32
#if defined (__linux__)
sl@0
    33
#  include <ieee754.h>
sl@0
    34
sl@0
    35
union _ll {
sl@0
    36
  uint64_t i64;
sl@0
    37
  struct {
sl@0
    38
#  if defined (_STLP_BIG_ENDIAN)
sl@0
    39
    uint32_t hi;
sl@0
    40
    uint32_t lo;
sl@0
    41
#  elif defined (_STLP_LITTLE_ENDIAN)
sl@0
    42
    uint32_t lo;
sl@0
    43
    uint32_t hi;
sl@0
    44
#  else
sl@0
    45
#    error Unknown endianess
sl@0
    46
#  endif
sl@0
    47
  } i32;
sl@0
    48
};
sl@0
    49
#endif
sl@0
    50
sl@0
    51
#if defined (N_PLAT_NLM)
sl@0
    52
#  include <nlm/nwintxx.h>
sl@0
    53
sl@0
    54
#  if defined (INT64)
sl@0
    55
typedef unsigned INT64 uint64_t;
sl@0
    56
#  else
sl@0
    57
// #error "Can't find INT64"
sl@0
    58
// 64-bit int really not defined in headers
sl@0
    59
// (_INTEGRAL_MAX_BITS < 64 in any case?), but compiler indeed know __int64
sl@0
    60
//        - ptr, 2005-05-06
sl@0
    61
typedef unsigned __int64 uint64_t;
sl@0
    62
#  endif
sl@0
    63
sl@0
    64
#  if defined (INT32)
sl@0
    65
typedef unsigned INT32 uint32_t;
sl@0
    66
#  else
sl@0
    67
#    error Can not find INT32
sl@0
    68
#  endif
sl@0
    69
sl@0
    70
union _ll {
sl@0
    71
  uint64_t i64;
sl@0
    72
  struct {
sl@0
    73
    uint32_t lo;
sl@0
    74
    uint32_t hi;
sl@0
    75
  } i32;
sl@0
    76
};
sl@0
    77
#endif
sl@0
    78
sl@0
    79
_STLP_BEGIN_NAMESPACE
sl@0
    80
_STLP_MOVE_TO_PRIV_NAMESPACE
sl@0
    81
sl@0
    82
//----------------------------------------------------------------------
sl@0
    83
// num_get
sl@0
    84
sl@0
    85
// Helper functions for _M_do_get_float.
sl@0
    86
sl@0
    87
#if !defined (_STLP_NO_WCHAR_T)
sl@0
    88
void  _STLP_DECLSPEC _STLP_CALL
sl@0
    89
_Initialize_get_float( const ctype<wchar_t>& ct,
sl@0
    90
                       wchar_t& Plus, wchar_t& Minus,
sl@0
    91
                       wchar_t& pow_e, wchar_t& pow_E,
sl@0
    92
                       wchar_t* digits) {
sl@0
    93
  char ndigits[11] = "0123456789";
sl@0
    94
  Plus  = ct.widen('+');
sl@0
    95
  Minus = ct.widen('-');
sl@0
    96
  pow_e = ct.widen('e');
sl@0
    97
  pow_E = ct.widen('E');
sl@0
    98
  ct.widen(ndigits + 0, ndigits + 10, digits);
sl@0
    99
}
sl@0
   100
#endif /* WCHAR_T */
sl@0
   101
sl@0
   102
/*
sl@0
   103
 * __string_to_double is just lifted from atof, the difference being
sl@0
   104
 * that we just use '.' for the decimal point, rather than let it
sl@0
   105
 * be taken from the current C locale, which of course is not accessible
sl@0
   106
 * to us.
sl@0
   107
 */
sl@0
   108
#if defined (_STLP_MSVC) || defined (__BORLANDC__) || defined (__ICL)
sl@0
   109
typedef unsigned long uint32;
sl@0
   110
typedef unsigned __int64 uint64;
sl@0
   111
#  define ULL(x) x##Ui64
sl@0
   112
#elif defined (__MRC__) || defined (__SC__)
sl@0
   113
typedef unsigned long uint32;
sl@0
   114
#  include "uint64.h"    //*TY 03/25/2000 - added 64bit math type definition
sl@0
   115
#elif defined (__unix) || defined (__MINGW32__) || defined (N_PLAT_NLM) || \
sl@0
   116
      (defined (__DMC__) && (__LONGLONG)) || defined(__SYMBIAN32__)
sl@0
   117
#if defined(__SYMBIAN32__)
sl@0
   118
#  include <sys/types.h>
sl@0
   119
#endif
sl@0
   120
typedef uint32_t uint32;
sl@0
   121
typedef uint64_t uint64;
sl@0
   122
#  define ULL(x) x##ULL
sl@0
   123
#else
sl@0
   124
#  error There should be some unsigned 64-bit integer on the system!
sl@0
   125
#endif
sl@0
   126
sl@0
   127
// Multiplication of two 64-bit integers, giving a 128-bit result.
sl@0
   128
// Taken from Algorithm M in Knuth section 4.3.1, with the loop
sl@0
   129
// hand-unrolled.
sl@0
   130
static void _Stl_mult64(const uint64 u, const uint64 v,
sl@0
   131
                        uint64& high, uint64& low) {
sl@0
   132
  const uint64 low_mask = ULL(0xffffffff);
sl@0
   133
  const uint64 u0 = u & low_mask;
sl@0
   134
  const uint64 u1 = u >> 32;
sl@0
   135
  const uint64 v0 = v & low_mask;
sl@0
   136
  const uint64 v1 = v >> 32;
sl@0
   137
sl@0
   138
  uint64 t = u0 * v0;
sl@0
   139
  low = t & low_mask;
sl@0
   140
sl@0
   141
  t = u1 * v0 + (t >> 32);
sl@0
   142
  uint64 w1 = t & low_mask;
sl@0
   143
  uint64 w2 = t >> 32;
sl@0
   144
sl@0
   145
  uint64 x = u0 * v1 + w1;
sl@0
   146
  low += (x & low_mask) << 32;
sl@0
   147
  high = u1 * v1 + w2 + (x >> 32);
sl@0
   148
}
sl@0
   149
sl@0
   150
#define bit11 ULL(0x7ff)
sl@0
   151
#define exponent_mask (bit11 << 52)
sl@0
   152
sl@0
   153
#if !defined (__GNUC__) || (__GNUC__ != 3) || (__GNUC_MINOR__ != 4) || \
sl@0
   154
    (!defined (__CYGWIN__) && !defined (__MINGW32__))
sl@0
   155
//Generate bad code when compiled with -O2 option.
sl@0
   156
inline
sl@0
   157
#endif
sl@0
   158
void _Stl_set_exponent(uint64 &val, uint64 exp)
sl@0
   159
{ val = (val & ~exponent_mask) | ((exp & bit11) << 52); }
sl@0
   160
sl@0
   161
/* Power of ten fractions for tenscale*/
sl@0
   162
/* The constants are factored so that at most two constants
sl@0
   163
 * and two multiplies are needed. Furthermore, one of the constants
sl@0
   164
 * is represented exactly - 10**n where 1<= n <= 27.
sl@0
   165
 */
sl@0
   166
sl@0
   167
#if !defined (__SC__)    //*TY 03/25/2000 - no native 64bit integer under SCpp
sl@0
   168
static const uint64 _Stl_tenpow[80] = {
sl@0
   169
ULL(0xa000000000000000), /* _Stl_tenpow[0]=(10**1)/(2**4) */
sl@0
   170
ULL(0xc800000000000000), /* _Stl_tenpow[1]=(10**2)/(2**7) */
sl@0
   171
ULL(0xfa00000000000000), /* _Stl_tenpow[2]=(10**3)/(2**10) */
sl@0
   172
ULL(0x9c40000000000000), /* _Stl_tenpow[3]=(10**4)/(2**14) */
sl@0
   173
ULL(0xc350000000000000), /* _Stl_tenpow[4]=(10**5)/(2**17) */
sl@0
   174
ULL(0xf424000000000000), /* _Stl_tenpow[5]=(10**6)/(2**20) */
sl@0
   175
ULL(0x9896800000000000), /* _Stl_tenpow[6]=(10**7)/(2**24) */
sl@0
   176
ULL(0xbebc200000000000), /* _Stl_tenpow[7]=(10**8)/(2**27) */
sl@0
   177
ULL(0xee6b280000000000), /* _Stl_tenpow[8]=(10**9)/(2**30) */
sl@0
   178
ULL(0x9502f90000000000), /* _Stl_tenpow[9]=(10**10)/(2**34) */
sl@0
   179
ULL(0xba43b74000000000), /* _Stl_tenpow[10]=(10**11)/(2**37) */
sl@0
   180
ULL(0xe8d4a51000000000), /* _Stl_tenpow[11]=(10**12)/(2**40) */
sl@0
   181
ULL(0x9184e72a00000000), /* _Stl_tenpow[12]=(10**13)/(2**44) */
sl@0
   182
ULL(0xb5e620f480000000), /* _Stl_tenpow[13]=(10**14)/(2**47) */
sl@0
   183
ULL(0xe35fa931a0000000), /* _Stl_tenpow[14]=(10**15)/(2**50) */
sl@0
   184
ULL(0x8e1bc9bf04000000), /* _Stl_tenpow[15]=(10**16)/(2**54) */
sl@0
   185
ULL(0xb1a2bc2ec5000000), /* _Stl_tenpow[16]=(10**17)/(2**57) */
sl@0
   186
ULL(0xde0b6b3a76400000), /* _Stl_tenpow[17]=(10**18)/(2**60) */
sl@0
   187
ULL(0x8ac7230489e80000), /* _Stl_tenpow[18]=(10**19)/(2**64) */
sl@0
   188
ULL(0xad78ebc5ac620000), /* _Stl_tenpow[19]=(10**20)/(2**67) */
sl@0
   189
ULL(0xd8d726b7177a8000), /* _Stl_tenpow[20]=(10**21)/(2**70) */
sl@0
   190
ULL(0x878678326eac9000), /* _Stl_tenpow[21]=(10**22)/(2**74) */
sl@0
   191
ULL(0xa968163f0a57b400), /* _Stl_tenpow[22]=(10**23)/(2**77) */
sl@0
   192
ULL(0xd3c21bcecceda100), /* _Stl_tenpow[23]=(10**24)/(2**80) */
sl@0
   193
ULL(0x84595161401484a0), /* _Stl_tenpow[24]=(10**25)/(2**84) */
sl@0
   194
ULL(0xa56fa5b99019a5c8), /* _Stl_tenpow[25]=(10**26)/(2**87) */
sl@0
   195
ULL(0xcecb8f27f4200f3a), /* _Stl_tenpow[26]=(10**27)/(2**90) */
sl@0
   196
sl@0
   197
ULL(0xd0cf4b50cfe20766), /* _Stl_tenpow[27]=(10**55)/(2**183) */
sl@0
   198
ULL(0xd2d80db02aabd62c), /* _Stl_tenpow[28]=(10**83)/(2**276) */
sl@0
   199
ULL(0xd4e5e2cdc1d1ea96), /* _Stl_tenpow[29]=(10**111)/(2**369) */
sl@0
   200
ULL(0xd6f8d7509292d603), /* _Stl_tenpow[30]=(10**139)/(2**462) */
sl@0
   201
ULL(0xd910f7ff28069da4), /* _Stl_tenpow[31]=(10**167)/(2**555) */
sl@0
   202
ULL(0xdb2e51bfe9d0696a), /* _Stl_tenpow[32]=(10**195)/(2**648) */
sl@0
   203
ULL(0xdd50f1996b947519), /* _Stl_tenpow[33]=(10**223)/(2**741) */
sl@0
   204
ULL(0xdf78e4b2bd342cf7), /* _Stl_tenpow[34]=(10**251)/(2**834) */
sl@0
   205
ULL(0xe1a63853bbd26451), /* _Stl_tenpow[35]=(10**279)/(2**927) */
sl@0
   206
ULL(0xe3d8f9e563a198e5), /* _Stl_tenpow[36]=(10**307)/(2**1020) */
sl@0
   207
sl@0
   208
ULL(0xfd87b5f28300ca0e), /* _Stl_tenpow[37]=(10**-28)/(2**-93) */
sl@0
   209
ULL(0xfb158592be068d2f), /* _Stl_tenpow[38]=(10**-56)/(2**-186) */
sl@0
   210
ULL(0xf8a95fcf88747d94), /* _Stl_tenpow[39]=(10**-84)/(2**-279) */
sl@0
   211
ULL(0xf64335bcf065d37d), /* _Stl_tenpow[40]=(10**-112)/(2**-372) */
sl@0
   212
ULL(0xf3e2f893dec3f126), /* _Stl_tenpow[41]=(10**-140)/(2**-465) */
sl@0
   213
ULL(0xf18899b1bc3f8ca2), /* _Stl_tenpow[42]=(10**-168)/(2**-558) */
sl@0
   214
ULL(0xef340a98172aace5), /* _Stl_tenpow[43]=(10**-196)/(2**-651) */
sl@0
   215
ULL(0xece53cec4a314ebe), /* _Stl_tenpow[44]=(10**-224)/(2**-744) */
sl@0
   216
ULL(0xea9c227723ee8bcb), /* _Stl_tenpow[45]=(10**-252)/(2**-837)     */
sl@0
   217
ULL(0xe858ad248f5c22ca), /* _Stl_tenpow[46]=(10**-280)/(2**-930) */
sl@0
   218
ULL(0xe61acf033d1a45df), /* _Stl_tenpow[47]=(10**-308)/(2**-1023)    */
sl@0
   219
ULL(0xe3e27a444d8d98b8), /* _Stl_tenpow[48]=(10**-336)/(2**-1116) */
sl@0
   220
ULL(0xe1afa13afbd14d6e)  /* _Stl_tenpow[49]=(10**-364)/(2**-1209) */
sl@0
   221
sl@0
   222
#else    //*TY 03/20/2000 - added support for SCpp which lacks native 64bit integer type
sl@0
   223
static const UnsignedWide _Stl_tenpow[80] = {
sl@0
   224
ULL2(0xa0000000,0x00000000), /* _Stl_tenpow[0]=(10**1)/(2**4) */
sl@0
   225
ULL2(0xc8000000,0x00000000), /* _Stl_tenpow[1]=(10**2)/(2**7) */
sl@0
   226
ULL2(0xfa000000,0x00000000), /* _Stl_tenpow[2]=(10**3)/(2**10) */
sl@0
   227
ULL2(0x9c400000,0x00000000), /* _Stl_tenpow[3]=(10**4)/(2**14) */
sl@0
   228
ULL2(0xc3500000,0x00000000), /* _Stl_tenpow[4]=(10**5)/(2**17) */
sl@0
   229
ULL2(0xf4240000,0x00000000), /* _Stl_tenpow[5]=(10**6)/(2**20) */
sl@0
   230
ULL2(0x98968000,0x00000000), /* _Stl_tenpow[6]=(10**7)/(2**24) */
sl@0
   231
ULL2(0xbebc2000,0x00000000), /* _Stl_tenpow[7]=(10**8)/(2**27) */
sl@0
   232
ULL2(0xee6b2800,0x00000000), /* _Stl_tenpow[8]=(10**9)/(2**30) */
sl@0
   233
ULL2(0x9502f900,0x00000000), /* _Stl_tenpow[9]=(10**10)/(2**34) */
sl@0
   234
ULL2(0xba43b740,0x00000000), /* _Stl_tenpow[10]=(10**11)/(2**37) */
sl@0
   235
ULL2(0xe8d4a510,0x00000000), /* _Stl_tenpow[11]=(10**12)/(2**40) */
sl@0
   236
ULL2(0x9184e72a,0x00000000), /* _Stl_tenpow[12]=(10**13)/(2**44) */
sl@0
   237
ULL2(0xb5e620f4,0x80000000), /* _Stl_tenpow[13]=(10**14)/(2**47) */
sl@0
   238
ULL2(0xe35fa931,0xa0000000), /* _Stl_tenpow[14]=(10**15)/(2**50) */
sl@0
   239
ULL2(0x8e1bc9bf,0x04000000), /* _Stl_tenpow[15]=(10**16)/(2**54) */
sl@0
   240
ULL2(0xb1a2bc2e,0xc5000000), /* _Stl_tenpow[16]=(10**17)/(2**57) */
sl@0
   241
ULL2(0xde0b6b3a,0x76400000), /* _Stl_tenpow[17]=(10**18)/(2**60) */
sl@0
   242
ULL2(0x8ac72304,0x89e80000), /* _Stl_tenpow[18]=(10**19)/(2**64) */
sl@0
   243
ULL2(0xad78ebc5,0xac620000), /* _Stl_tenpow[19]=(10**20)/(2**67) */
sl@0
   244
ULL2(0xd8d726b7,0x177a8000), /* _Stl_tenpow[20]=(10**21)/(2**70) */
sl@0
   245
ULL2(0x87867832,0x6eac9000), /* _Stl_tenpow[21]=(10**22)/(2**74) */
sl@0
   246
ULL2(0xa968163f,0x0a57b400), /* _Stl_tenpow[22]=(10**23)/(2**77) */
sl@0
   247
ULL2(0xd3c21bce,0xcceda100), /* _Stl_tenpow[23]=(10**24)/(2**80) */
sl@0
   248
ULL2(0x84595161,0x401484a0), /* _Stl_tenpow[24]=(10**25)/(2**84) */
sl@0
   249
ULL2(0xa56fa5b9,0x9019a5c8), /* _Stl_tenpow[25]=(10**26)/(2**87) */
sl@0
   250
ULL2(0xcecb8f27,0xf4200f3a), /* _Stl_tenpow[26]=(10**27)/(2**90) */
sl@0
   251
sl@0
   252
ULL2(0xd0cf4b50,0xcfe20766), /* _Stl_tenpow[27]=(10**55)/(2**183) */
sl@0
   253
ULL2(0xd2d80db0,0x2aabd62c), /* _Stl_tenpow[28]=(10**83)/(2**276) */
sl@0
   254
ULL2(0xd4e5e2cd,0xc1d1ea96), /* _Stl_tenpow[29]=(10**111)/(2**369) */
sl@0
   255
ULL2(0xd6f8d750,0x9292d603), /* _Stl_tenpow[30]=(10**139)/(2**462) */
sl@0
   256
ULL2(0xd910f7ff,0x28069da4), /* _Stl_tenpow[31]=(10**167)/(2**555) */
sl@0
   257
ULL2(0xdb2e51bf,0xe9d0696a), /* _Stl_tenpow[32]=(10**195)/(2**648) */
sl@0
   258
ULL2(0xdd50f199,0x6b947519), /* _Stl_tenpow[33]=(10**223)/(2**741) */
sl@0
   259
ULL2(0xdf78e4b2,0xbd342cf7), /* _Stl_tenpow[34]=(10**251)/(2**834) */
sl@0
   260
ULL2(0xe1a63853,0xbbd26451), /* _Stl_tenpow[35]=(10**279)/(2**927) */
sl@0
   261
ULL2(0xe3d8f9e5,0x63a198e5), /* _Stl_tenpow[36]=(10**307)/(2**1020) */
sl@0
   262
sl@0
   263
ULL2(0xfd87b5f2,0x8300ca0e), /* _Stl_tenpow[37]=(10**-28)/(2**-93) */
sl@0
   264
ULL2(0xfb158592,0xbe068d2f), /* _Stl_tenpow[38]=(10**-56)/(2**-186) */
sl@0
   265
ULL2(0xf8a95fcf,0x88747d94), /* _Stl_tenpow[39]=(10**-84)/(2**-279) */
sl@0
   266
ULL2(0xf64335bc,0xf065d37d), /* _Stl_tenpow[40]=(10**-112)/(2**-372) */
sl@0
   267
ULL2(0xf3e2f893,0xdec3f126), /* _Stl_tenpow[41]=(10**-140)/(2**-465) */
sl@0
   268
ULL2(0xf18899b1,0xbc3f8ca2), /* _Stl_tenpow[42]=(10**-168)/(2**-558) */
sl@0
   269
ULL2(0xef340a98,0x172aace5), /* _Stl_tenpow[43]=(10**-196)/(2**-651) */
sl@0
   270
ULL2(0xece53cec,0x4a314ebe), /* _Stl_tenpow[44]=(10**-224)/(2**-744) */
sl@0
   271
ULL2(0xea9c2277,0x23ee8bcb), /* _Stl_tenpow[45]=(10**-252)/(2**-837)     */
sl@0
   272
ULL2(0xe858ad24,0x8f5c22ca), /* _Stl_tenpow[46]=(10**-280)/(2**-930) */
sl@0
   273
ULL2(0xe61acf03,0x3d1a45df), /* _Stl_tenpow[47]=(10**-308)/(2**-1023)    */
sl@0
   274
ULL2(0xe3e27a44,0x4d8d98b8), /* _Stl_tenpow[48]=(10**-336)/(2**-1116) */
sl@0
   275
ULL2(0xe1afa13a,0xfbd14d6e)  /* _Stl_tenpow[49]=(10**-364)/(2**-1209) */
sl@0
   276
#endif
sl@0
   277
};
sl@0
   278
sl@0
   279
static const short _Stl_twoexp[80] = {
sl@0
   280
4,7,10,14,17,20,24,27,30,34,37,40,44,47,50,54,57,60,64,67,70,74,77,80,84,87,90,
sl@0
   281
183,276,369,462,555,648,741,834,927,1020,
sl@0
   282
-93,-186,-279,-372,-465,-558,-651,-744,-837,-930,-1023,-1116,-1209
sl@0
   283
};
sl@0
   284
sl@0
   285
#define  TEN_1  0           /* offset to 10 **   1 */
sl@0
   286
#define  TEN_27   26        /* offset to 10 **  27 */
sl@0
   287
#define  TEN_M28  37        /* offset to 10 ** -28 */
sl@0
   288
#define  NUM_HI_P 11
sl@0
   289
#define  NUM_HI_N 13
sl@0
   290
sl@0
   291
#define _Stl_HIBITULL (ULL(1) << 63)
sl@0
   292
sl@0
   293
static void _Stl_norm_and_round(uint64& p, int& norm, uint64 prodhi, uint64 prodlo) {
sl@0
   294
  norm = 0;
sl@0
   295
  if ((prodhi & _Stl_HIBITULL) == 0) {
sl@0
   296
                                /* leading bit is a zero
sl@0
   297
                                 * may have to normalize
sl@0
   298
                                 */
sl@0
   299
    if ((prodhi == ~_Stl_HIBITULL) &&
sl@0
   300
        ((prodlo >> 62) == 0x3)) {  /* normalization followed by round
sl@0
   301
                                     * would cause carry to create
sl@0
   302
                                     * extra bit, so don't normalize
sl@0
   303
                                     */
sl@0
   304
      p = _Stl_HIBITULL;
sl@0
   305
      return;
sl@0
   306
    }
sl@0
   307
    p = (prodhi << 1) | (prodlo >> 63); /* normalize */
sl@0
   308
    norm = 1;
sl@0
   309
    prodlo <<= 1;
sl@0
   310
  }
sl@0
   311
  else {
sl@0
   312
    p = prodhi;
sl@0
   313
  }
sl@0
   314
sl@0
   315
  if ((prodlo & _Stl_HIBITULL) != 0) {     /* first guard bit a one */    //*TY 03/25/2000 - added explicit comparison to zero to avoid reliance to the implicit conversion from uint64 to bool
sl@0
   316
#if !defined (__SC__)                  //*TY 03/25/2000 -
sl@0
   317
    if (((p & 0x1) != 0) ||
sl@0
   318
        prodlo != _Stl_HIBITULL ) {    /* not borderline for round to even */
sl@0
   319
#else                                 //*TY 03/25/2000 - added workaround for SCpp compiler
sl@0
   320
    bool b1 = ((p & 0x1) != 0);
sl@0
   321
    if (b1 || prodlo != _Stl_HIBITULL) { //*TY 03/25/2000 - SCpp confuses on this particular original boolean expression
sl@0
   322
#endif                                    //*TY 03/25/2000 -
sl@0
   323
      /* round */
sl@0
   324
      ++p;
sl@0
   325
      if (p == 0)
sl@0
   326
        ++p;
sl@0
   327
    }
sl@0
   328
  }
sl@0
   329
sl@0
   330
  return;
sl@0
   331
}
sl@0
   332
sl@0
   333
// Convert a 64-bitb fraction * 10^exp to a 64-bit fraction * 2^bexp.
sl@0
   334
// p:    64-bit fraction
sl@0
   335
// exp:  base-10 exponent
sl@0
   336
// bexp: base-2 exponent (output parameter)
sl@0
   337
static void _Stl_tenscale(uint64& p, int exp, int& bexp) {
sl@0
   338
  uint64 prodhi, prodlo;        /* 128b product */
sl@0
   339
  int exp_hi, exp_lo;           /* exp = exp_hi*32 + exp_lo */
sl@0
   340
  int hi, lo, tlo, thi;         /* offsets in power of ten table */
sl@0
   341
  int norm;                     /* number of bits of normalization */
sl@0
   342
  int num_hi;                   /* number of high exponent powers */
sl@0
   343
sl@0
   344
  bexp = 0;
sl@0
   345
  if (exp > 0) {                 /* split exponent */
sl@0
   346
    exp_lo = exp;
sl@0
   347
    exp_hi = 0;
sl@0
   348
    if (exp_lo > 27) {
sl@0
   349
      exp_lo++;
sl@0
   350
      while (exp_lo > 27) {
sl@0
   351
        exp_hi++;
sl@0
   352
        exp_lo -= 28;
sl@0
   353
      }
sl@0
   354
    }
sl@0
   355
    tlo = TEN_1;
sl@0
   356
    thi = TEN_27;
sl@0
   357
    num_hi = NUM_HI_P;
sl@0
   358
  }
sl@0
   359
  else if (exp < 0) {
sl@0
   360
    exp_lo = exp;
sl@0
   361
    exp_hi = 0;
sl@0
   362
    while (exp_lo < 0) {
sl@0
   363
      exp_hi++;
sl@0
   364
      exp_lo += 28;
sl@0
   365
    }
sl@0
   366
    tlo = TEN_1;
sl@0
   367
    thi = TEN_M28;
sl@0
   368
    num_hi = NUM_HI_N;
sl@0
   369
  }
sl@0
   370
  else {                        /* no scaling needed */
sl@0
   371
    return;
sl@0
   372
  }
sl@0
   373
  while (exp_hi) {               /* scale */
sl@0
   374
    hi = (min) (exp_hi, num_hi);    /* only a few large powers of 10 */
sl@0
   375
    exp_hi -= hi;               /* could iterate in extreme case */
sl@0
   376
    hi += thi-1;
sl@0
   377
    _Stl_mult64(p, _Stl_tenpow[hi], prodhi, prodlo);
sl@0
   378
    _Stl_norm_and_round(p, norm, prodhi, prodlo);
sl@0
   379
    bexp += _Stl_twoexp[hi] - norm;
sl@0
   380
  }
sl@0
   381
  if (exp_lo) {
sl@0
   382
    lo = tlo + exp_lo -1;
sl@0
   383
    _Stl_mult64(p, _Stl_tenpow[lo], prodhi, prodlo);
sl@0
   384
    _Stl_norm_and_round(p, norm, prodhi, prodlo);
sl@0
   385
    bexp += _Stl_twoexp[lo] - norm;
sl@0
   386
  }
sl@0
   387
sl@0
   388
  return;
sl@0
   389
}
sl@0
   390
sl@0
   391
// First argument is a buffer of values from 0 to 9, NOT ascii.
sl@0
   392
// Second argument is number of digits in buffer, 1 <= digits <= 17.
sl@0
   393
// Third argument is base-10 exponent.
sl@0
   394
sl@0
   395
#if defined (__SC__) || defined (__MRC__)
sl@0
   396
sl@0
   397
//*TY 04/06/2000 - powermac's 68K emulator utilizes apple's SANE floating point, which is not compatible with IEEE format.
sl@0
   398
_STLP_MOVE_TO_STD_NAMESPACE
sl@0
   399
_STLP_END_NAMESPACE
sl@0
   400
sl@0
   401
#  include <fp.h>
sl@0
   402
sl@0
   403
_STLP_BEGIN_NAMESPACE
sl@0
   404
_STLP_MOVE_TO_PRIV_NAMESPACE
sl@0
   405
sl@0
   406
static inline double _Stl_atod(char *buffer, int ndigit, int dexp) {
sl@0
   407
  decimal d;  // ref. inside macintosh powerpc numerics p.9-13
sl@0
   408
sl@0
   409
  d.sgn = 0;
sl@0
   410
  d.exp = dexp;
sl@0
   411
  d.sig.length = ndigit;
sl@0
   412
  for (int i = 0; i < ndigit; ++i) {
sl@0
   413
    d.sig.text[i] = buffer[i] + '0';
sl@0
   414
  }
sl@0
   415
  return dec2num(&d);
sl@0
   416
}
sl@0
   417
sl@0
   418
#else  /* IEEE representation */
sl@0
   419
sl@0
   420
#  if !defined (__linux__)
sl@0
   421
static double _Stl_atod(char *buffer, int ndigit, int dexp) {
sl@0
   422
  uint64 value;         /* Value develops as follows:
sl@0
   423
                                 * 1) decimal digits as an integer
sl@0
   424
                                 * 2) left adjusted fraction
sl@0
   425
                                 * 3) right adjusted fraction
sl@0
   426
                                 * 4) exponent and fraction
sl@0
   427
                                 */
sl@0
   428
sl@0
   429
  uint32 guard;         /* First guard bit */
sl@0
   430
  uint64 rest;          /* Remaining guard bits */
sl@0
   431
sl@0
   432
  int bexp;             /* binary exponent */
sl@0
   433
  int nzero;            /* number of non-zero bits */
sl@0
   434
  int sexp;             /* scaling exponent */
sl@0
   435
sl@0
   436
  char *bufferend;              /* pointer to char after last digit */
sl@0
   437
sl@0
   438
  /* Check for zero and treat it as a special case */
sl@0
   439
  if (buffer == 0){
sl@0
   440
    return 0.0;
sl@0
   441
  }
sl@0
   442
sl@0
   443
  /* Convert the decimal digits to a binary integer. */
sl@0
   444
sl@0
   445
  bufferend = buffer + ndigit;
sl@0
   446
  value = 0;
sl@0
   447
sl@0
   448
  while (buffer < bufferend) {
sl@0
   449
    value *= 10;
sl@0
   450
    value += *buffer++;
sl@0
   451
  }
sl@0
   452
sl@0
   453
  /* Check for zero and treat it as a special case */
sl@0
   454
  if (value == 0) {
sl@0
   455
    return 0.0;
sl@0
   456
  }
sl@0
   457
sl@0
   458
  /* Normalize value */
sl@0
   459
  bexp = 64;                    /* convert from 64b int to fraction */
sl@0
   460
sl@0
   461
  /* Count number of non-zeroes in value */
sl@0
   462
  nzero = 0;
sl@0
   463
  if ((value >> 32) != 0) { nzero  = 32; }    //*TY 03/25/2000 - added explicit comparison to zero to avoid uint64 to bool conversion operator
sl@0
   464
  if ((value >> (16 + nzero)) != 0) { nzero += 16; }
sl@0
   465
  if ((value >> ( 8 + nzero)) != 0) { nzero +=  8; }
sl@0
   466
  if ((value >> ( 4 + nzero)) != 0) { nzero +=  4; }
sl@0
   467
  if ((value >> ( 2 + nzero)) != 0) { nzero +=  2; }
sl@0
   468
  if ((value >> ( 1 + nzero)) != 0) { nzero +=  1; }
sl@0
   469
  if ((value >> (     nzero)) != 0) { nzero +=  1; }
sl@0
   470
sl@0
   471
  /* Normalize */
sl@0
   472
  value <<= /*(uint64)*/ (64 - nzero);    //*TY 03/25/2000 - removed extraneous cast to uint64
sl@0
   473
  bexp -= 64 - nzero;
sl@0
   474
sl@0
   475
  /* At this point we have a 64b fraction and a binary exponent
sl@0
   476
   * but have yet to incorporate the decimal exponent.
sl@0
   477
   */
sl@0
   478
sl@0
   479
  /* multiply by 10^dexp */
sl@0
   480
  _Stl_tenscale(value, dexp, sexp);
sl@0
   481
  bexp += sexp;
sl@0
   482
sl@0
   483
  if (bexp <= -1022) {          /* HI denorm or underflow */
sl@0
   484
    bexp += 1022;
sl@0
   485
    if (bexp < -53) {          /* guaranteed underflow */
sl@0
   486
      value = 0;
sl@0
   487
    }
sl@0
   488
    else {                      /* denorm or possible underflow */
sl@0
   489
      int lead0 = 12 - bexp;          /* 12 sign and exponent bits */
sl@0
   490
sl@0
   491
      /* we must special case right shifts of more than 63 */
sl@0
   492
      if (lead0 > 64) {
sl@0
   493
        rest = value;
sl@0
   494
        guard = 0;
sl@0
   495
        value = 0;
sl@0
   496
      }
sl@0
   497
      else if (lead0 == 64) {
sl@0
   498
        rest = value & ((ULL(1)<< 63)-1);
sl@0
   499
#if !defined(__SC__)
sl@0
   500
        guard = (uint32) ((value>> 63) & 1 );
sl@0
   501
#else
sl@0
   502
        guard = to_ulong((value>> 63) & 1 );   //*TY 03/25/2000 - use member function instead of problematic conversion operator utilization
sl@0
   503
#endif
sl@0
   504
        value = 0;
sl@0
   505
      }
sl@0
   506
      else {
sl@0
   507
        rest = value & (((ULL(1) << lead0)-1)-1);
sl@0
   508
#if !defined(__SC__)
sl@0
   509
        guard = (uint32) (((value>> lead0)-1) & 1);
sl@0
   510
#else     //*TY 03/25/2000 -
sl@0
   511
        guard = to_ulong(((value>> lead0)-1) & 1);
sl@0
   512
#endif    //*TY 03/25/2000 -
sl@0
   513
        value >>= /*(uint64)*/ lead0; /* exponent is zero */
sl@0
   514
      }
sl@0
   515
sl@0
   516
      /* Round */
sl@0
   517
      if (guard && ((value & 1) || rest) ) {
sl@0
   518
        ++value;
sl@0
   519
        if (value == (ULL(1) << 52)) { /* carry created normal number */
sl@0
   520
          value = 0;
sl@0
   521
          _Stl_set_exponent(value, 1);
sl@0
   522
        }
sl@0
   523
      }
sl@0
   524
    }
sl@0
   525
  }
sl@0
   526
  else {                        /* not zero or denorm */
sl@0
   527
    /* Round to 53 bits */
sl@0
   528
    rest = value & (1<<10)-1;
sl@0
   529
    value >>= 10;
sl@0
   530
#if !defined(__SC__)
sl@0
   531
    guard = (uint32) value & 1;
sl@0
   532
#else    //*TY 03/25/2000 -
sl@0
   533
    guard = to_ulong(value & 1);
sl@0
   534
#endif
sl@0
   535
    value >>= 1;
sl@0
   536
sl@0
   537
    /*  value&1 guard   rest    Action
sl@0
   538
     *
sl@0
   539
     *  dc      0       dc      none
sl@0
   540
     *  1       1       dc      round
sl@0
   541
     *  0       1       0       none
sl@0
   542
     *  0       1       !=0     round
sl@0
   543
     */
sl@0
   544
    if (guard) {
sl@0
   545
      if (((value&1)!=0) || (rest!=0)) {
sl@0
   546
        ++value;                        /* round */
sl@0
   547
        if ((value >> 53) != 0) {       /* carry all the way across */
sl@0
   548
          value >>= 1;          /* renormalize */
sl@0
   549
          ++bexp;
sl@0
   550
        }
sl@0
   551
      }
sl@0
   552
    }
sl@0
   553
    /*
sl@0
   554
     * Check for overflow
sl@0
   555
     * IEEE Double Precision Format
sl@0
   556
     * (From Table 7-8 of Kane and Heinrich)
sl@0
   557
     *
sl@0
   558
     * Fraction bits               52
sl@0
   559
     * Emax                     +1023
sl@0
   560
     * Emin                     -1022
sl@0
   561
     * Exponent bias            +1023
sl@0
   562
     * Exponent bits               11
sl@0
   563
     * Integer bit             hidden
sl@0
   564
     * Total width in bits         64
sl@0
   565
     */
sl@0
   566
sl@0
   567
    if (bexp > 1024) {          /* overflow */
sl@0
   568
      return numeric_limits<double>::infinity();
sl@0
   569
    }
sl@0
   570
    else {                      /* value is normal */
sl@0
   571
      value &= ~(ULL(1) << 52);   /* hide hidden bit */
sl@0
   572
      _Stl_set_exponent(value, bexp + 1022); /* add bias */
sl@0
   573
    }
sl@0
   574
  }
sl@0
   575
sl@0
   576
  _STLP_STATIC_ASSERT(sizeof(value) == sizeof(double))
sl@0
   577
  return *((double *) &value);
sl@0
   578
}
sl@0
   579
sl@0
   580
#  else // __linux__
sl@0
   581
sl@0
   582
static double _Stl_atod(char *buffer, int ndigit, int dexp) {
sl@0
   583
  ieee754_double v;
sl@0
   584
sl@0
   585
  char *bufferend;              /* pointer to char after last digit */
sl@0
   586
sl@0
   587
  /* Check for zero and treat it as a special case */
sl@0
   588
sl@0
   589
  if (buffer == 0) {
sl@0
   590
    return 0.0;
sl@0
   591
  }
sl@0
   592
sl@0
   593
  /* Convert the decimal digits to a binary integer. */
sl@0
   594
sl@0
   595
  bufferend = buffer + ndigit;
sl@0
   596
  _ll vv;
sl@0
   597
  vv.i64 = 0L;
sl@0
   598
sl@0
   599
  while (buffer < bufferend) {
sl@0
   600
    vv.i64 *= 10;
sl@0
   601
    vv.i64 += *buffer++;
sl@0
   602
  }
sl@0
   603
sl@0
   604
  /* Check for zero and treat it as a special case */
sl@0
   605
  if (vv.i64 == 0){
sl@0
   606
    return 0.0;
sl@0
   607
  }
sl@0
   608
sl@0
   609
  /* Normalize value */
sl@0
   610
  int bexp = 64;                    /* convert from 64b int to fraction */
sl@0
   611
sl@0
   612
  /* Count number of non-zeroes in value */
sl@0
   613
  int nzero = 0;
sl@0
   614
  if ((vv.i64 >> 32) !=0 ) { nzero  = 32; }    //*TY 03/25/2000 - added explicit comparison to zero to avoid uint64 to bool conversion operator
sl@0
   615
  if ((vv.i64 >> (16 + nzero)) != 0) { nzero += 16; }
sl@0
   616
  if ((vv.i64 >> ( 8 + nzero)) != 0) { nzero +=  8; }
sl@0
   617
  if ((vv.i64 >> ( 4 + nzero)) != 0) { nzero +=  4; }
sl@0
   618
  if ((vv.i64 >> ( 2 + nzero)) != 0) { nzero +=  2; }
sl@0
   619
  if ((vv.i64 >> ( 1 + nzero)) != 0) { nzero +=  1; }
sl@0
   620
  if ((vv.i64 >> (     nzero)) != 0) { nzero +=  1; }
sl@0
   621
sl@0
   622
  /* Normalize */
sl@0
   623
  nzero = 64 - nzero;
sl@0
   624
  vv.i64 <<= nzero;    //*TY 03/25/2000 - removed extraneous cast to uint64
sl@0
   625
  bexp -= nzero;
sl@0
   626
sl@0
   627
  /* At this point we have a 64b fraction and a binary exponent
sl@0
   628
   * but have yet to incorporate the decimal exponent.
sl@0
   629
   */
sl@0
   630
sl@0
   631
  /* multiply by 10^dexp */
sl@0
   632
  int sexp;
sl@0
   633
  _Stl_tenscale(vv.i64, dexp, sexp);
sl@0
   634
  bexp += sexp;
sl@0
   635
sl@0
   636
  if (bexp <= -1022) {          /* HI denorm or underflow */
sl@0
   637
    bexp += 1022;
sl@0
   638
    if (bexp < -53) {           /* guaranteed underflow */
sl@0
   639
      vv.i64 = 0;
sl@0
   640
    }
sl@0
   641
    else {                      /* denorm or possible underflow */
sl@0
   642
      int lead0;
sl@0
   643
      uint64_t rest;
sl@0
   644
      uint32_t guard;
sl@0
   645
sl@0
   646
      lead0 = 12-bexp;          /* 12 sign and exponent bits */
sl@0
   647
sl@0
   648
      /* we must special case right shifts of more than 63 */
sl@0
   649
      if (lead0 > 64) {
sl@0
   650
        rest = vv.i64;
sl@0
   651
        guard = 0;
sl@0
   652
        vv.i64 = 0;
sl@0
   653
      }
sl@0
   654
      else if (lead0 == 64) {
sl@0
   655
        rest = vv.i64 & ((ULL(1) << 63)-1);
sl@0
   656
#if !defined(__SC__)
sl@0
   657
        guard = (uint32) ((vv.i64 >> 63) & 1 );
sl@0
   658
#else
sl@0
   659
        guard = to_ulong((vv.i64 >> 63) & 1 );   //*TY 03/25/2000 - use member function instead of problematic conversion operator utilization
sl@0
   660
#endif
sl@0
   661
        vv.i64 = 0;
sl@0
   662
      }
sl@0
   663
      else {
sl@0
   664
        rest = vv.i64 & (((ULL(1) << lead0)-1)-1);
sl@0
   665
#if !defined(__SC__)
sl@0
   666
        guard = (uint32) (((vv.i64 >> lead0)-1) & 1);
sl@0
   667
#else     //*TY 03/25/2000 -
sl@0
   668
        guard = to_ulong(((vv.i64 >> lead0)-1) & 1);
sl@0
   669
#endif    //*TY 03/25/2000 -
sl@0
   670
        vv.i64 >>= /*(uint64)*/ lead0; /* exponent is zero */
sl@0
   671
      }
sl@0
   672
sl@0
   673
      /* Round */
sl@0
   674
      if (guard && ( (vv.i64 & 1) || rest)) {
sl@0
   675
        vv.i64++;
sl@0
   676
        if (vv.i64 == (ULL(1) << 52)) { /* carry created normal number */
sl@0
   677
          v.ieee.mantissa0 = 0;
sl@0
   678
          v.ieee.mantissa1 = 0;
sl@0
   679
          v.ieee.negative = 0;
sl@0
   680
          v.ieee.exponent = 1;
sl@0
   681
          return v.d;
sl@0
   682
        }
sl@0
   683
      }
sl@0
   684
    }
sl@0
   685
  }
sl@0
   686
  else {                        /* not zero or denorm */
sl@0
   687
    /* Round to 53 bits */
sl@0
   688
    uint64_t rest = vv.i64 & (1<<10)-1;
sl@0
   689
    vv.i64 >>= 10;
sl@0
   690
#if !defined(__SC__)
sl@0
   691
    uint32_t guard = (uint32) vv.i64 & 1;
sl@0
   692
#else    //*TY 03/25/2000 -
sl@0
   693
    uint32_t guard = to_ulong(vv.i64 & 1);
sl@0
   694
#endif
sl@0
   695
    vv.i64 >>= 1;
sl@0
   696
sl@0
   697
    /*  value&1 guard   rest    Action
sl@0
   698
     *
sl@0
   699
     *  dc      0       dc      none
sl@0
   700
     *  1       1       dc      round
sl@0
   701
     *  0       1       0       none
sl@0
   702
     *  0       1       !=0     round
sl@0
   703
     */
sl@0
   704
    if (guard) {
sl@0
   705
      if (((vv.i64&1)!=0) || (rest!=0)) {
sl@0
   706
        vv.i64++;                        /* round */
sl@0
   707
        if ((vv.i64>>53)!=0) {         /* carry all the way across */
sl@0
   708
          vv.i64 >>= 1;          /* renormalize */
sl@0
   709
          ++bexp;
sl@0
   710
        }
sl@0
   711
      }
sl@0
   712
    }
sl@0
   713
    /*
sl@0
   714
     * Check for overflow
sl@0
   715
     * IEEE Double Precision Format
sl@0
   716
     * (From Table 7-8 of Kane and Heinrich)
sl@0
   717
     *
sl@0
   718
     * Fraction bits               52
sl@0
   719
     * Emax                     +1023
sl@0
   720
     * Emin                     -1022
sl@0
   721
     * Exponent bias            +1023
sl@0
   722
     * Exponent bits               11
sl@0
   723
     * Integer bit             hidden
sl@0
   724
     * Total width in bits         64
sl@0
   725
     */
sl@0
   726
sl@0
   727
    if (bexp > 1024) {          /* overflow */
sl@0
   728
      return numeric_limits<double>::infinity();
sl@0
   729
    }
sl@0
   730
    else {                      /* value is normal */
sl@0
   731
      vv.i64 &= ~(ULL(1) << 52);   /* hide hidden bit */
sl@0
   732
      v.ieee.mantissa0 = vv.i32.hi;
sl@0
   733
      v.ieee.mantissa1 = vv.i32.lo;
sl@0
   734
      v.ieee.negative = 0;
sl@0
   735
      v.ieee.exponent = bexp + 1022;
sl@0
   736
      return v.d;
sl@0
   737
    }
sl@0
   738
  }
sl@0
   739
sl@0
   740
  v.ieee.mantissa0 = vv.i32.hi;
sl@0
   741
  v.ieee.mantissa1 = vv.i32.lo;
sl@0
   742
  v.ieee.negative = 0;
sl@0
   743
  v.ieee.exponent = 0;
sl@0
   744
sl@0
   745
  return v.d;
sl@0
   746
}
sl@0
   747
#  endif // __linux__
sl@0
   748
sl@0
   749
#endif
sl@0
   750
sl@0
   751
static double _Stl_string_to_double(const char *s) {
sl@0
   752
  const int max_digits = 17;
sl@0
   753
  unsigned c;
sl@0
   754
  unsigned Negate, decimal_point;
sl@0
   755
  char *d;
sl@0
   756
  int exp;
sl@0
   757
  double x;
sl@0
   758
  int dpchar;
sl@0
   759
  char digits[max_digits];
sl@0
   760
sl@0
   761
  // Skip leading whitespace, if any.
sl@0
   762
  const ctype<char>& ct = use_facet<ctype<char> >(locale::classic());
sl@0
   763
  while (c = *s++, ct.is(ctype_base::space, char(c))) {}
sl@0
   764
sl@0
   765
  /* process sign */
sl@0
   766
  Negate = 0;
sl@0
   767
  if (c == '+') {
sl@0
   768
    c = *s++;
sl@0
   769
  }
sl@0
   770
  else if (c == '-') {
sl@0
   771
    Negate = 1;
sl@0
   772
    c = *s++;
sl@0
   773
  }
sl@0
   774
  d = digits;
sl@0
   775
  dpchar = '.' - '0';
sl@0
   776
  decimal_point = 0;
sl@0
   777
  exp = 0;
sl@0
   778
  for (;;) {
sl@0
   779
    c -= '0';
sl@0
   780
    if (c < 10) {
sl@0
   781
      if (d == digits + max_digits) {
sl@0
   782
        /* ignore more than 17 digits, but adjust exponent */
sl@0
   783
        exp += (decimal_point ^ 1);
sl@0
   784
      }
sl@0
   785
      else {
sl@0
   786
        if (c == 0 && d == digits) {
sl@0
   787
          /* ignore leading zeros */
sl@0
   788
        }
sl@0
   789
        else {
sl@0
   790
          *d++ = (char) c;
sl@0
   791
        }
sl@0
   792
        exp -= decimal_point;
sl@0
   793
      }
sl@0
   794
    }
sl@0
   795
    else if (c == (unsigned int) dpchar && !decimal_point) {    /* INTERNATIONAL */
sl@0
   796
      decimal_point = 1;
sl@0
   797
    }
sl@0
   798
    else {
sl@0
   799
      break;
sl@0
   800
    }
sl@0
   801
    c = *s++;
sl@0
   802
  }
sl@0
   803
  /* strtod cant return until it finds the end of the exponent */
sl@0
   804
  if (d == digits) {
sl@0
   805
    return 0.0;
sl@0
   806
  }
sl@0
   807
sl@0
   808
  if (c == 'e'-'0' || c == 'E'-'0') {
sl@0
   809
    register unsigned negate_exp = 0;
sl@0
   810
    register int e = 0;
sl@0
   811
    c = *s++;
sl@0
   812
    if (c == '+' || c == ' ') {
sl@0
   813
      c = *s++;
sl@0
   814
    }
sl@0
   815
    else if (c == '-') {
sl@0
   816
      negate_exp = 1;
sl@0
   817
      c = *s++;
sl@0
   818
    }
sl@0
   819
    if (c -= '0', c < 10) {
sl@0
   820
      do {
sl@0
   821
        if (e <= 340)
sl@0
   822
          e = e * 10 + (int)c;
sl@0
   823
        else break;
sl@0
   824
        c = *s++;
sl@0
   825
      }
sl@0
   826
      while (c -= '0', c < 10);
sl@0
   827
      if (negate_exp) {
sl@0
   828
        e = -e;
sl@0
   829
      }
sl@0
   830
      if (e < -340 || e > 340)
sl@0
   831
        exp = e;
sl@0
   832
      else
sl@0
   833
        exp += e;
sl@0
   834
    }
sl@0
   835
  }
sl@0
   836
sl@0
   837
  if (exp < -340) {
sl@0
   838
    x = 0;
sl@0
   839
  }
sl@0
   840
  else if (exp > 308) {
sl@0
   841
    x = numeric_limits<double>::infinity();
sl@0
   842
  }
sl@0
   843
  else {
sl@0
   844
    /* let _Stl_atod diagnose under- and over-flows */
sl@0
   845
    /* if the input was == 0.0, we have already returned,
sl@0
   846
       so retval of +-Inf signals OVERFLOW, 0.0 UNDERFLOW
sl@0
   847
    */
sl@0
   848
    x = _Stl_atod(digits, (int)(d - digits), exp);
sl@0
   849
  }
sl@0
   850
  if (Negate) {
sl@0
   851
    x = -x;
sl@0
   852
  }
sl@0
   853
  return x;
sl@0
   854
}
sl@0
   855
sl@0
   856
sl@0
   857
#if !defined (_STLP_NO_LONG_DOUBLE)
sl@0
   858
/*
sl@0
   859
 * __string_to_long_double is just lifted from atold, the difference being
sl@0
   860
 * that we just use '.' for the decimal point, rather than let it
sl@0
   861
 * be taken from the current C locale, which of course is not accessible
sl@0
   862
 * to us.
sl@0
   863
 */
sl@0
   864
sl@0
   865
static long double
sl@0
   866
_Stl_string_to_long_double(const char * s) {
sl@0
   867
  const int max_digits = 34;
sl@0
   868
  register unsigned c;
sl@0
   869
  register unsigned Negate, decimal_point;
sl@0
   870
  register char *d;
sl@0
   871
  register int exp;
sl@0
   872
  long double x;
sl@0
   873
  register int dpchar;
sl@0
   874
  char digits[max_digits];
sl@0
   875
sl@0
   876
  const ctype<char>& ct = use_facet<ctype<char> >(locale::classic());
sl@0
   877
  while (c = *s++, ct.is(ctype_base::space, char(c)))
sl@0
   878
    ;
sl@0
   879
sl@0
   880
  /* process sign */
sl@0
   881
  Negate = 0;
sl@0
   882
  if (c == '+') {
sl@0
   883
    c = *s++;
sl@0
   884
  }
sl@0
   885
  else if (c == '-') {
sl@0
   886
    Negate = 1;
sl@0
   887
    c = *s++;
sl@0
   888
  }
sl@0
   889
sl@0
   890
  d = digits;
sl@0
   891
  dpchar = '.' - '0';
sl@0
   892
  decimal_point = 0;
sl@0
   893
  exp = 0;
sl@0
   894
sl@0
   895
  for (;;) {
sl@0
   896
    c -= '0';
sl@0
   897
    if (c < 10) {
sl@0
   898
      if (d == digits+max_digits) {
sl@0
   899
        /* ignore more than 34 digits, but adjust exponent */
sl@0
   900
        exp += (decimal_point ^ 1);
sl@0
   901
      }
sl@0
   902
      else {
sl@0
   903
        if (c == 0 && d == digits) {
sl@0
   904
          /* ignore leading zeros */
sl@0
   905
          ;
sl@0
   906
        }
sl@0
   907
        else {
sl@0
   908
          *d++ = (char)c;
sl@0
   909
        }
sl@0
   910
        exp -= decimal_point;
sl@0
   911
      }
sl@0
   912
    }
sl@0
   913
    else if ((char)c == dpchar && !decimal_point) {    /* INTERNATIONAL */
sl@0
   914
      decimal_point = 1;
sl@0
   915
    }
sl@0
   916
    else {
sl@0
   917
      break;
sl@0
   918
    }
sl@0
   919
    c = *s++;
sl@0
   920
  } /* for */
sl@0
   921
sl@0
   922
  if (d == digits) {
sl@0
   923
    return 0.0L;
sl@0
   924
  }
sl@0
   925
  if (c == 'e'-'0' || c == 'E'-'0') {
sl@0
   926
    register unsigned negate_exp = 0;
sl@0
   927
    register int e = 0;
sl@0
   928
    c = *s++;
sl@0
   929
    if (c == '+' || c == ' ') {
sl@0
   930
      c = *s++;
sl@0
   931
    }
sl@0
   932
    else if (c == '-') {
sl@0
   933
      negate_exp = 1;
sl@0
   934
      c = *s++;
sl@0
   935
    }
sl@0
   936
    if (c -= '0', c < 10) {
sl@0
   937
      do {
sl@0
   938
        if (e <= 340)
sl@0
   939
          e = e * 10 + c;
sl@0
   940
        else break;
sl@0
   941
        c = *s++;
sl@0
   942
      }
sl@0
   943
      while (c -= '0', c < 10);
sl@0
   944
      if (negate_exp) {
sl@0
   945
        e = -e;
sl@0
   946
      }
sl@0
   947
      if (e < -(323+max_digits) || e > 308)
sl@0
   948
        exp = e;
sl@0
   949
      else
sl@0
   950
        exp += e;
sl@0
   951
    }
sl@0
   952
  }
sl@0
   953
sl@0
   954
  if (exp < -(324+max_digits)) {
sl@0
   955
    x = 0;
sl@0
   956
  }
sl@0
   957
  else if (exp > 308) {
sl@0
   958
    x =  numeric_limits<long double>::infinity();
sl@0
   959
  }
sl@0
   960
  else {
sl@0
   961
    /* let _Stl_atod diagnose under- and over-flows */
sl@0
   962
    /* if the input was == 0.0, we have already returned,
sl@0
   963
           so retval of +-Inf signals OVERFLOW, 0.0 UNDERFLOW
sl@0
   964
        */
sl@0
   965
sl@0
   966
    //    x = _Stl_atod (digits, (int)(d - digits), exp); // TEMPORARY!!:1
sl@0
   967
    double tmp = _Stl_atod (digits, (int)(d - digits), exp); // TEMPORARY!!:1
sl@0
   968
    x = tmp == numeric_limits<double>::infinity()
sl@0
   969
      ? numeric_limits<long double>::infinity()
sl@0
   970
      : tmp;
sl@0
   971
  }
sl@0
   972
sl@0
   973
  if (Negate) {
sl@0
   974
    x = -x;
sl@0
   975
  }
sl@0
   976
sl@0
   977
  return x;
sl@0
   978
}
sl@0
   979
#endif
sl@0
   980
sl@0
   981
void  _STLP_DECLSPEC _STLP_CALL
sl@0
   982
__string_to_float(const __iostring& v, float& val)
sl@0
   983
{ val = (float)_Stl_string_to_double(v.c_str()); }
sl@0
   984
sl@0
   985
void _STLP_DECLSPEC _STLP_CALL
sl@0
   986
__string_to_float(const __iostring& v, double& val)
sl@0
   987
{ val = _Stl_string_to_double(v.c_str()); }
sl@0
   988
sl@0
   989
#if !defined (_STLP_NO_LONG_DOUBLE)
sl@0
   990
void _STLP_DECLSPEC _STLP_CALL
sl@0
   991
__string_to_float(const __iostring& v, long double& val)
sl@0
   992
{ val = _Stl_string_to_long_double(v.c_str()); }
sl@0
   993
#endif
sl@0
   994
sl@0
   995
_STLP_MOVE_TO_STD_NAMESPACE
sl@0
   996
_STLP_END_NAMESPACE
sl@0
   997
sl@0
   998
// Local Variables:
sl@0
   999
// mode:C++
sl@0
  1000
// End: