php-internal-docs
8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
mysql_float_to_double.h
Go to the documentation of this file.
1
/*
2
+----------------------------------------------------------------------+
3
| Copyright (c) The PHP Group |
4
+----------------------------------------------------------------------+
5
| This source file is subject to version 3.01 of the PHP license, |
6
| that is bundled with this package in the file LICENSE, and is |
7
| available through the world-wide-web at the following url: |
8
| https://www.php.net/license/3_01.txt |
9
| If you did not receive a copy of the PHP license and are unable to |
10
| obtain it through the world-wide-web, please send a note to |
11
| license@php.net so we can mail you a copy immediately. |
12
+----------------------------------------------------------------------+
13
| Authors: Keyur Govande <kgovande@gmail.com> |
14
+----------------------------------------------------------------------+
15
*/
16
17
#ifndef MYSQL_FLOAT_TO_DOUBLE_H
18
#define MYSQL_FLOAT_TO_DOUBLE_H
19
20
#include "
main/php.h
"
21
#include <float.h>
22
#include "
main/snprintf.h
"
23
24
#define MAX_CHAR_BUF_LEN 255
25
26
#ifndef FLT_DIG
27
# define FLT_DIG 6
28
#endif
29
30
/*
31
* Convert from a 4-byte float to a 8-byte decimal by first converting
32
* the float to a string (ignoring localization), and then the string to a double.
33
* The decimals argument specifies the precision of the output. If decimals
34
* is less than zero, then a gcvt(3) like logic is used with the significant
35
* digits set to FLT_DIG i.e. 6.
36
*/
37
static
inline
double
mysql_float_to_double(
float
fp4,
int
decimals) {
38
char
num_buf[
MAX_CHAR_BUF_LEN
];
/* Over allocated */
39
40
if
(decimals < 0) {
41
zend_gcvt
(fp4,
FLT_DIG
,
'.'
,
'e'
, num_buf);
42
}
else
{
43
snprintf
(num_buf,
MAX_CHAR_BUF_LEN
,
"%.*F"
, decimals, fp4);
44
}
45
46
return
zend_strtod
(num_buf,
NULL
);
47
}
48
49
#endif
/* MYSQL_FLOAT_TO_DOUBLE_H */
NULL
#define NULL
Definition
gdcache.h:45
FLT_DIG
#define FLT_DIG
Definition
mysql_float_to_double.h:27
MAX_CHAR_BUF_LEN
#define MAX_CHAR_BUF_LEN
Definition
mysql_float_to_double.h:24
php.h
snprintf.h
snprintf
#define snprintf
Definition
zend_config.w32.h:42
zend_strtod
ZEND_API double zend_strtod(const char *s00, const char **se)
Definition
zend_strtod.c:2525
zend_gcvt
ZEND_API char * zend_gcvt(double value, int ndigit, char dec_point, char exponent, char *buf)
Definition
zend_strtod.c:4513
ext
mysqlnd
mysql_float_to_double.h
Generated on Sat Aug 23 2025 01:46:09 for php-internal-docs by
1.13.2