Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert float to ascii using g_fmt and zend_dtoa.
This procudes much smaller textual representations and also ignores locales.
- Loading branch information
Showing
4 changed files
with
161 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,99 @@ | |||
/**************************************************************** | |||
* | |||
* The author of this software is David M. Gay. | |||
* | |||
* Copyright (c) 1991, 1996 by Lucent Technologies. | |||
* | |||
* Permission to use, copy, modify, and distribute this software for any | |||
* purpose without fee is hereby granted, provided that this entire notice | |||
* is included in all copies of any software which is or includes a copy | |||
* or modification of this software and in all copies of the supporting | |||
* documentation for such software. | |||
* | |||
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED | |||
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY | |||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY | |||
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. | |||
* | |||
***************************************************************/ | |||
|
|||
/* g_fmt(buf,x) stores the closest decimal approximation to x in buf; | |||
* it suffices to declare buf | |||
* char buf[32]; | |||
*/ | |||
|
|||
/* Modified for use with php in the memcached client extension. | |||
* | |||
* // Teddy Grenman <teddy.grenman@iki.fi>, 2010-05-18. | |||
*/ | |||
|
|||
#include <zend_operators.h> | |||
|
|||
char *php_memcached_g_fmt(register char *b, double x) { | |||
register int i, k; | |||
register char *s; | |||
int decpt, j, sign; | |||
char *b0, *s0, *se; | |||
|
|||
b0 = b; | |||
#ifdef IGNORE_ZERO_SIGN | |||
if (!x) { | |||
*b++ = '0'; | |||
*b = 0; | |||
goto done; | |||
} | |||
#endif | |||
|
|||
s = s0 = zend_dtoa(x, 0, 0, &decpt, &sign, &se); | |||
if (sign) | |||
*b++ = '-'; | |||
if (decpt == 9999) /* Infinity or Nan */ { | |||
while(*b++ = *s++); | |||
goto done0; | |||
} | |||
if (decpt <= -4 || decpt > se - s + 5) { | |||
*b++ = *s++; | |||
if (*s) { | |||
*b++ = '.'; | |||
while(*b = *s++) | |||
b++; | |||
} | |||
*b++ = 'e'; | |||
/* sprintf(b, "%+.2d", decpt - 1); */ | |||
if (--decpt < 0) { | |||
*b++ = '-'; | |||
decpt = -decpt; | |||
} | |||
else | |||
*b++ = '+'; | |||
for(j = 2, k = 10; 10*k <= decpt; j++, k *= 10); | |||
for(;;) { | |||
i = decpt / k; | |||
*b++ = i + '0'; | |||
if (--j <= 0) | |||
break; | |||
decpt -= i*k; | |||
decpt *= 10; | |||
} | |||
*b = 0; | |||
} else if (decpt <= 0) { | |||
*b++ = '.'; | |||
for(; decpt < 0; decpt++) | |||
*b++ = '0'; | |||
while(*b++ = *s++); | |||
} else { | |||
while(*b = *s++) { | |||
b++; | |||
if (--decpt == 0 && *s) | |||
*b++ = '.'; | |||
} | |||
for(; decpt > 0; decpt--) | |||
*b++ = '0'; | |||
*b = 0; | |||
} | |||
|
|||
done0: | |||
zend_freedtoa(s0); | |||
done: | |||
return b0; | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,34 @@ | |||
/**************************************************************** | |||
* | |||
* The author of this software is David M. Gay. | |||
* | |||
* Copyright (c) 1991, 1996 by Lucent Technologies. | |||
* | |||
* Permission to use, copy, modify, and distribute this software for any | |||
* purpose without fee is hereby granted, provided that this entire notice | |||
* is included in all copies of any software which is or includes a copy | |||
* or modification of this software and in all copies of the supporting | |||
* documentation for such software. | |||
* | |||
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED | |||
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY | |||
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY | |||
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. | |||
* | |||
***************************************************************/ | |||
|
|||
/* g_fmt(buf,x) stores the closest decimal approximation to x in buf; | |||
* it suffices to declare buf | |||
* char buf[32]; | |||
*/ | |||
|
|||
/* Modified for use with php in the memcached client | |||
* extension by Teddy Grenman, 2010. | |||
*/ | |||
|
|||
#ifndef MEMC_G_FMT_H | |||
#define MEMC_G_FMT_H | |||
|
|||
char *php_memcached_g_fmt(register char *b, double x); | |||
|
|||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters