~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to strings/longlong2str.c

MergedĀ fromĀ trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/*
17
 
  Defines: longlong2str();
 
17
  Defines: int64_t2str();
18
18
 
19
 
  longlong2str(dst, radix, val)
20
 
  converts the (longlong) integer "val" to character form and moves it to
 
19
  int64_t2str(dst, radix, val)
 
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
23
  is dud the result will be NullS and nothing will be changed.
40
40
#include <my_global.h>
41
41
#include "m_string.h"
42
42
 
43
 
#if !defined(longlong2str) && !defined(HAVE_LONGLONG2STR)
 
43
#if !defined(int64_t2str) && !defined(HAVE_LONGLONG2STR)
44
44
 
45
45
/*
46
 
  This assumes that longlong multiplication is faster than longlong division.
 
46
  This assumes that int64_t multiplication is faster than int64_t division.
47
47
*/
48
48
 
49
 
char *longlong2str(longlong val,char *dst,int radix)
 
49
char *int64_t2str(int64_t val,char *dst,int radix)
50
50
{
51
51
  char buffer[65];
52
52
  register char *p;
53
53
  long long_val;
54
 
  ulonglong uval= (ulonglong) val;
 
54
  uint64_t uval= (uint64_t) val;
55
55
 
56
56
  if (radix < 0)
57
57
  {
59
59
    if (val < 0) {
60
60
      *dst++ = '-';
61
61
      /* Avoid integer overflow in (-val) for LONGLONG_MIN (BUG#31799). */
62
 
      uval = (ulonglong)0 - uval;
 
62
      uval = (uint64_t)0 - uval;
63
63
    }
64
64
    radix = -radix;
65
65
  }
76
76
  p = &buffer[sizeof(buffer)-1];
77
77
  *p = '\0';
78
78
 
79
 
  while (uval > (ulonglong) LONG_MAX)
 
79
  while (uval > (uint64_t) LONG_MAX)
80
80
  {
81
 
    ulonglong quo= uval/(uint) radix;
 
81
    uint64_t quo= uval/(uint) radix;
82
82
    uint rem= (uint) (uval- quo* (uint) radix);
83
83
    *--p = _dig_vec_upper[rem];
84
84
    uval= quo;
96
96
 
97
97
#endif
98
98
 
99
 
#ifndef longlong10_to_str
100
 
char *longlong10_to_str(longlong val,char *dst,int radix)
 
99
#ifndef int64_t10_to_str
 
100
char *int64_t10_to_str(int64_t val,char *dst,int radix)
101
101
{
102
102
  char buffer[65];
103
103
  register char *p;
104
104
  long long_val;
105
 
  ulonglong uval= (ulonglong) val;
 
105
  uint64_t uval= (uint64_t) val;
106
106
 
107
107
  if (radix < 0)
108
108
  {
110
110
    {
111
111
      *dst++ = '-';
112
112
      /* Avoid integer overflow in (-val) for LONGLONG_MIN (BUG#31799). */
113
 
      uval = (ulonglong)0 - uval;
 
113
      uval = (uint64_t)0 - uval;
114
114
    }
115
115
  }
116
116
 
123
123
  p = &buffer[sizeof(buffer)-1];
124
124
  *p = '\0';
125
125
 
126
 
  while (uval > (ulonglong) LONG_MAX)
 
126
  while (uval > (uint64_t) LONG_MAX)
127
127
  {
128
 
    ulonglong quo= uval/(uint) 10;
 
128
    uint64_t quo= uval/(uint) 10;
129
129
    uint rem= (uint) (uval- quo* (uint) 10);
130
130
    *--p = _dig_vec_upper[rem];
131
131
    uval= quo;