~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/longlong2str.cc

  • Committer: Brian Aker
  • Date: 2009-12-29 01:38:38 UTC
  • mfrom: (1251.1.1 drizzle)
  • Revision ID: brian@gaz-20091229013838-03kb2z5xbqw03ddt
Merge of Diego fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
  converts the (int64_t) integer "val" to character form and moves it to
21
21
  the destination string "dst" followed by a terminating NUL.  The
22
22
  result is normally a pointer to this NUL character, but if the radix
23
 
  is dud the result will be NullS and nothing will be changed.
 
23
  is dud the result will be NULL and nothing will be changed.
24
24
 
25
25
  If radix is -2..-36, val is taken to be SIGNED.
26
26
  If radix is  2.. 36, val is taken to be UNSIGNED.
37
37
        itoa assumes that 10 -base numbers are allways signed and other arn't.
38
38
*/
39
39
 
 
40
#include "config.h"
 
41
 
40
42
#include "m_string.h"
41
43
 
42
44
#if !defined(int64_t2str) && !defined(HAVE_LONGLONG2STR)
43
45
 
 
46
char _dig_vec_upper[] =
 
47
  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 
48
 
44
49
/*
45
50
  This assumes that int64_t multiplication is faster than int64_t division.
46
51
*/
77
82
 
78
83
  while (uval > (uint64_t) LONG_MAX)
79
84
  {
80
 
    uint64_t quo= uval/(uint) radix;
81
 
    uint rem= (uint) (uval- quo* (uint) radix);
 
85
    uint64_t quo= uval/(uint32_t) radix;
 
86
    uint32_t rem= (uint32_t) (uval- quo* (uint32_t) radix);
82
87
    *--p = _dig_vec_upper[rem];
83
88
    uval= quo;
84
89
  }
86
91
  while (long_val != 0)
87
92
  {
88
93
    long quo= long_val/radix;
89
 
    *--p = _dig_vec_upper[(uchar) (long_val - quo*radix)];
 
94
    *--p = _dig_vec_upper[(unsigned char) (long_val - quo*radix)];
90
95
    long_val= quo;
91
96
  }
92
97
  while ((*dst++ = *p++) != 0) ;
124
129
 
125
130
  while (uval > (uint64_t) LONG_MAX)
126
131
  {
127
 
    uint64_t quo= uval/(uint) 10;
128
 
    uint rem= (uint) (uval- quo* (uint) 10);
 
132
    uint64_t quo= uval/(uint32_t) 10;
 
133
    uint32_t rem= (uint32_t) (uval- quo* (uint32_t) 10);
129
134
    *--p = _dig_vec_upper[rem];
130
135
    uval= quo;
131
136
  }
133
138
  while (long_val != 0)
134
139
  {
135
140
    long quo= long_val/10;
136
 
    *--p = _dig_vec_upper[(uchar) (long_val - quo*10)];
 
141
    *--p = _dig_vec_upper[(unsigned char) (long_val - quo*10)];
137
142
    long_val= quo;
138
143
  }
139
144
  while ((*dst++ = *p++) != 0) ;