~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to strings/dtoa.c

Renamed more stuff to drizzle.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
 
36
36
 ***************************************************************/
37
37
 
 
38
#include <my_base.h> /* for EOVERFLOW on Windows */
 
39
#include <my_global.h>
38
40
#include <m_string.h>  /* for memcpy and NOT_FIXED_DEC */
39
41
 
40
42
/**
77
79
                      (including the terminating '\0').
78
80
   @param error       if not NULL, points to a location where the status of
79
81
                      conversion is stored upon return.
80
 
                      false  successful conversion
81
 
                      true   the input number is [-,+]infinity or nan.
 
82
                      FALSE  successful conversion
 
83
                      TRUE   the input number is [-,+]infinity or nan.
82
84
                             The output string in this case is always '0'.
83
85
   @return            number of written characters (excluding terminating '\0')
84
86
*/
85
87
 
86
 
size_t my_fcvt(double x, int precision, char *to, bool *error)
 
88
size_t my_fcvt(double x, int precision, char *to, my_bool *error)
87
89
{
88
90
  int decpt, sign, len, i;
89
91
  char *res, *src, *end, *dst= to;
90
92
  char buf[DTOA_BUFF_SIZE];
91
 
  assert(precision >= 0 && precision < NOT_FIXED_DEC && to != NULL);
 
93
  DBUG_ASSERT(precision >= 0 && precision < NOT_FIXED_DEC && to != NULL);
92
94
  
93
95
  res= dtoa(x, 5, precision, &decpt, &sign, &end, buf, sizeof(buf));
94
96
 
98
100
    *to++= '0';
99
101
    *to= '\0';
100
102
    if (error != NULL)
101
 
      *error= true;
 
103
      *error= TRUE;
102
104
    return 1;
103
105
  }
104
106
 
136
138
  
137
139
  *dst= '\0';
138
140
  if (error != NULL)
139
 
    *error= false;
 
141
    *error= FALSE;
140
142
 
141
143
  dtoa_free(res, buf, sizeof(buf));
142
144
 
179
181
                      'width + 1' bytes.
180
182
   @param error       if not NULL, points to a location where the status of
181
183
                      conversion is stored upon return.
182
 
                      false  successful conversion
183
 
                      true   the input number is [-,+]infinity or nan.
 
184
                      FALSE  successful conversion
 
185
                      TRUE   the input number is [-,+]infinity or nan.
184
186
                             The output string in this case is always '0'.
185
187
   @return            number of written characters (excluding terminating '\0')
186
188
 
207
209
*/
208
210
 
209
211
size_t my_gcvt(double x, my_gcvt_arg_type type, int width, char *to,
210
 
               bool *error)
 
212
               my_bool *error)
211
213
{
212
214
  int decpt, sign, len, exp_len;
213
215
  char *res, *src, *end, *dst= to, *dend= dst + width;
214
216
  char buf[DTOA_BUFF_SIZE];
215
 
  bool have_space, force_e_format;
216
 
  assert(width > 0 && to != NULL);
 
217
  my_bool have_space, force_e_format;
 
218
  DBUG_ASSERT(width > 0 && to != NULL);
217
219
  
218
220
  /* We want to remove '-' from equations early */
219
221
  if (x < 0.)
227
229
    *to++= '0';
228
230
    *to= '\0';
229
231
    if (error != NULL)
230
 
      *error= true;
 
232
      *error= TRUE;
231
233
    return 1;
232
234
  }
233
235
 
234
236
  if (error != NULL)
235
 
    *error= false;
 
237
    *error= FALSE;
236
238
 
237
239
  src= res;
238
240
  len= end - res;
315
317
      if (width < decpt)
316
318
      {
317
319
        if (error != NULL)
318
 
          *error= true;
 
320
          *error= TRUE;
319
321
        width= decpt;
320
322
      }
321
323
      
382
384
    {
383
385
      /* Overflow */
384
386
      if (error != NULL)
385
 
        *error= true;
 
387
        *error= TRUE;
386
388
      width= 0;
387
389
    }
388
390
      
459
461
{
460
462
  char buf[DTOA_BUFF_SIZE];
461
463
  double res;
462
 
  assert(str != NULL && end != NULL && *end != NULL && error != NULL);
 
464
  DBUG_ASSERT(str != NULL && end != NULL && *end != NULL && error != NULL);
463
465
 
464
466
  res= my_strtod_int(str, end, error, buf, sizeof(buf));
465
467
  return (*error == 0) ? res : (res < 0 ? -DBL_MAX : DBL_MAX);
537
539
  TODO: check if we can get rid of the above two
538
540
*/
539
541
 
540
 
typedef int32_t Long;
541
 
typedef uint32_t ULong;
542
 
typedef int64_t LLong;
543
 
typedef uint64_t ULLong;
 
542
typedef int32 Long;
 
543
typedef uint32 ULong;
 
544
typedef int64 LLong;
 
545
typedef uint64 ULLong;
544
546
 
545
547
typedef union { double d; ULong L[2]; } U;
546
548
 
611
613
 
612
614
#define Kmax 15
613
615
 
614
 
#define Bcopy(x,y) memcpy(&x->sign, &y->sign, \
 
616
#define Bcopy(x,y) memcpy((char *)&x->sign, (char *)&y->sign,   \
615
617
                          2*sizeof(int) + y->wds*sizeof(ULong))
616
618
 
617
619
/* Arbitrary-length integer */
1327
1329
  double aadj, aadj1, adj, rv, rv0;
1328
1330
  Long L;
1329
1331
  ULong y, z;
1330
 
  Bigint *bb= NULL, *bb1= NULL, *bd= NULL, *bd0= NULL, *bs= NULL, *delta= NULL;
 
1332
  Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
1331
1333
#ifdef SET_INEXACT
1332
1334
  int inexact, oldinexact;
1333
1335
#endif
1336
1338
#endif
1337
1339
  Stack_alloc alloc;
1338
1340
 
1339
 
  c= 0;
1340
1341
  *error= 0;
1341
1342
 
1342
1343
  alloc.begin= alloc.free= buf;
2158
2159
    to hold the suppressed trailing zeros.
2159
2160
  */
2160
2161
 
2161
 
  int bbits, b2, b5, be, dig, i, ieps, ilim=0, ilim0, ilim1= 0,
 
2162
  int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1= 0,
2162
2163
    j, j1, k, k0, k_check, leftright, m2, m5, s2, s5,
2163
2164
    spec_case, try_quick;
2164
2165
  Long L;
2165
2166
  int denorm;
2166
2167
  ULong x;
2167
 
  Bigint *b, *b1, *delta, *mlo = NULL, *mhi, *S;
 
2168
  Bigint *b, *b1, *delta, *mlo, *mhi, *S;
2168
2169
  double d2, ds, eps;
2169
2170
  char *s, *s0;
2170
2171
#ifdef Honor_FLT_ROUNDS