本文整理汇总了C++中zend_strtod函数的典型用法代码示例。如果您正苦于以下问题:C++ zend_strtod函数的具体用法?C++ zend_strtod怎么用?C++ zend_strtod使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zend_strtod函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: json_create_zval
static void json_create_zval(zval **z, smart_str *buf, int type)
{
ALLOC_INIT_ZVAL(*z);
if (type == IS_LONG)
{
double d = zend_strtod(buf->c, NULL);
if (d > LONG_MAX || d < -LONG_MAX) {
ZVAL_DOUBLE(*z, d);
} else {
ZVAL_LONG(*z, (long)d);
}
}
else if (type == IS_DOUBLE)
{
ZVAL_DOUBLE(*z, zend_strtod(buf->c, NULL));
}
else if (type == IS_STRING)
{
ZVAL_STRINGL(*z, buf->c, buf->len, 1);
}
else if (type == IS_BOOL)
{
ZVAL_BOOL(*z, (*(buf->c) == 't'));
}
else /* type == IS_NULL) || type unknown */
{
ZVAL_NULL(*z);
}
}
示例2: php_bencode_decode_int
static void php_bencode_decode_int(zval *return_value, char *str, size_t *pos, size_t *str_len) /* {{{ */
{
int len = 0;
double d;
smart_str buf = {0};
(*pos)++;
while (*pos < *str_len && str[*pos] != PHP_BENCODE_END_STRUCTURE) {
smart_str_appendc(&buf, str[*pos]);
(*pos)++;
len++;
}
smart_str_0(&buf);
if (str[*pos] != PHP_BENCODE_END_STRUCTURE) {
smart_str_free(&buf);
zend_error(E_WARNING, "Invaild bencoded-integer, expected 'e'.");
RETURN_NULL();
}
(*pos)++;
ZVAL_STRINGL(return_value, ZSTR_VAL(buf.s), len);
d = zend_strtod(ZSTR_VAL(buf.s), NULL);
if (d <= ZEND_LONG_MAX && d >= ZEND_LONG_MIN) {
convert_to_long(return_value);
}
smart_str_free(&buf);
}
示例3: check
double VariableUnserializer::readDouble() {
check();
const char* newBuf;
double r = zend_strtod(m_buf, &newBuf);
m_buf = newBuf;
return r;
}
示例4: json_create_zval
static void json_create_zval(zval **z, smart_str *buf, int type, int options)
{
ALLOC_INIT_ZVAL(*z);
if (type == IS_LONG)
{
zend_bool bigint = 0;
if (buf->c[0] == '-') {
buf->len--;
}
if (buf->len >= MAX_LENGTH_OF_LONG - 1) {
if (buf->len == MAX_LENGTH_OF_LONG - 1) {
int cmp = strcmp(buf->c + (buf->c[0] == '-'), long_min_digits);
if (!(cmp < 0 || (cmp == 0 && buf->c[0] == '-'))) {
bigint = 1;
}
} else {
bigint = 1;
}
}
if (bigint) {
/* value too large to represent as a long */
if (options & PHP_JSON_BIGINT_AS_STRING) {
if (buf->c[0] == '-') {
/* Restore last char consumed above */
buf->len++;
}
goto use_string;
} else {
goto use_double;
}
}
ZVAL_LONG(*z, strtol(buf->c, NULL, 10));
}
else if (type == IS_DOUBLE)
{
use_double:
ZVAL_DOUBLE(*z, zend_strtod(buf->c, NULL));
}
else if (type == IS_STRING)
{
use_string:
ZVAL_STRINGL(*z, buf->c, buf->len, 1);
}
else if (type == IS_BOOL)
{
ZVAL_BOOL(*z, (*(buf->c) == 't'));
}
else /* type == IS_NULL) || type unknown */
{
ZVAL_NULL(*z);
}
}
示例5: ZEND_INI_MH
ZEND_API ZEND_INI_MH(OnUpdateReal) /* {{{ */
{
double *p;
#ifndef ZTS
char *base = (char *) mh_arg2;
#else
char *base;
base = (char *) ts_resource(*((int *) mh_arg2));
#endif
p = (double *) (base+(size_t) mh_arg1);
*p = zend_strtod(new_value, NULL);
return SUCCESS;
}
示例6: json_create_zval
static void json_create_zval(zval **z, smart_str *buf, int type TSRMLS_DC)
{
ALLOC_INIT_ZVAL(*z);
if (type == IS_LONG)
{
if (buf->c[0] == '-') {
buf->len--;
}
if (buf->len >= MAX_LENGTH_OF_LONG - 1) {
if (buf->len == MAX_LENGTH_OF_LONG - 1) {
int cmp = strcmp(buf->c + (buf->c[0] == '-'), long_min_digits);
if (!(cmp < 0 || (cmp == 0 && buf->c[0] == '-'))) {
goto use_double;
}
} else {
goto use_double;
}
}
ZVAL_LONG(*z, strtol(buf->c, NULL, 10));
}
else if (type == IS_DOUBLE)
{
use_double:
ZVAL_DOUBLE(*z, zend_strtod(buf->c, NULL));
}
else if (type == IS_STRING)
{
ZVAL_UTF8_STRINGL(*z, buf->c, buf->len, ZSTR_DUPLICATE);
}
else if (type == IS_BOOL)
{
ZVAL_BOOL(*z, (*(buf->c) == 't'));
}
else /* type == IS_NULL) || type unknown */
{
ZVAL_NULL(*z);
}
}
示例7: php_oci_collection_element_set_number
/* {{{ php_oci_collection_element_set_number()
Change element's value to the given NUMBER */
int php_oci_collection_element_set_number(php_oci_collection *collection, zend_long index, char *number, int number_len)
{
OCIInd new_index = OCI_IND_NOTNULL;
double element_double;
OCINumber oci_number;
php_oci_connection *connection = collection->connection;
sword errstatus;
element_double = zend_strtod(number, NULL);
PHP_OCI_CALL_RETURN(errstatus, OCINumberFromReal, (connection->err, &element_double, sizeof(double), &oci_number));
if (errstatus != OCI_SUCCESS) {
connection->errcode = php_oci_error(connection->err, errstatus);
PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
return 1;
}
PHP_OCI_CALL_RETURN(errstatus, OCICollAssignElem,
(
connection->env,
connection->err,
(ub4) index,
(dvoid *) &oci_number,
(dvoid *) &new_index,
(OCIColl *) collection->collection
)
);
if (errstatus != OCI_SUCCESS) {
connection->errcode = php_oci_error(connection->err, errstatus);
PHP_OCI_HANDLE_ERROR(connection, connection->errcode);
return 1;
}
connection->errcode = 0; /* retain backwards compat with OCI8 1.4 */
return 0;
}
示例8: slice
double StringData::toDouble() const {
auto s = slice();
if (s.size()) return zend_strtod(s.data(), nullptr);
return 0;
}
示例9: collator_u_strtod
static double collator_u_strtod(const UChar *nptr, UChar **endptr) {
const UChar *u = nptr, *nstart;
UChar c = *u;
int any = 0;
while (u_isspace(c)) {
c = *++u;
}
nstart = u;
if (c == 0x2D /*'-'*/ || c == 0x2B /*'+'*/) {
c = *++u;
}
while (c >= 0x30 /*'0'*/ && c <= 0x39 /*'9'*/) {
any = 1;
c = *++u;
}
if (c == 0x2E /*'.'*/) {
c = *++u;
while (c >= 0x30 /*'0'*/ && c <= 0x39 /*'9'*/) {
any = 1;
c = *++u;
}
}
if ((c == 0x65 /*'e'*/ || c == 0x45 /*'E'*/) && any) {
const UChar *e = u;
int any_exp = 0;
c = *++u;
if (c == 0x2D /*'-'*/ || c == 0x2B /*'+'*/) {
c = *++u;
}
while (c >= 0x30 /*'0'*/ && c <= 0x39 /*'9'*/) {
any_exp = 1;
c = *++u;
}
if (!any_exp) {
u = e;
}
}
if (any) {
char buf[64], *numbuf, *bufpos;
int length = u - nstart;
double value;
if (length < (int)sizeof(buf)) {
numbuf = buf;
} else {
numbuf = (char *) malloc(length + 1);
}
bufpos = numbuf;
while (nstart < u) {
*bufpos++ = (char) *nstart++;
}
*bufpos = '\0';
value = zend_strtod(numbuf, nullptr);
if (numbuf != buf) {
free(numbuf);
}
if (endptr != nullptr) {
*endptr = (UChar *)u;
}
return value;
}
if (endptr != nullptr) {
*endptr = (UChar *)nptr;
}
return 0;
}
示例10: _php_math_round
/*
* Rounds a number to a certain number of decimal places in a certain rounding
* mode. For the specifics of the algorithm, see http://wiki.php.net/rfc/rounding
*/
PHPAPI double _php_math_round(double value, int places, int mode) {
double f1, f2;
double tmp_value;
int precision_places;
if (!php_math_is_finite(value)) {
return value;
}
precision_places = 14 - php_intlog10abs(value);
f1 = php_intpow10(abs(places));
/* If the decimal precision guaranteed by FP arithmetic is higher than
the requested places BUT is small enough to make sure a non-zero value
is returned, pre-round the result to the precision */
if (precision_places > places && precision_places - places < 15) {
f2 = php_intpow10(abs(precision_places));
if (precision_places >= 0) {
tmp_value = value * f2;
} else {
tmp_value = value / f2;
}
/* preround the result (tmp_value will always be something * 1e14,
thus never larger than 1e15 here) */
tmp_value = php_round_helper(tmp_value, mode);
/* now correctly move the decimal point */
f2 = php_intpow10(abs(places - precision_places));
/* because places < precision_places */
tmp_value = tmp_value / f2;
} else {
/* adjust the value */
if (places >= 0) {
tmp_value = value * f1;
} else {
tmp_value = value / f1;
}
/* This value is beyond our precision, so rounding it is pointless */
if (fabs(tmp_value) >= 1e15) {
return value;
}
}
/* round the temp value */
tmp_value = php_round_helper(tmp_value, mode);
/* see if it makes sense to use simple division to round the value */
if (abs(places) < 23) {
if (places > 0) {
tmp_value = tmp_value / f1;
} else {
tmp_value = tmp_value * f1;
}
} else {
/* Simple division can't be used since that will cause wrong results.
Instead, the number is converted to a string and back again using
strtod(). strtod() will return the nearest possible FP value for
that string. */
/* 40 Bytes should be more than enough for this format string. The
float won't be larger than 1e15 anyway. But just in case, use
snprintf() and make sure the buffer is zero-terminated */
char buf[40];
snprintf(buf, 39, "%15fe%d", tmp_value, -places);
buf[39] = '\0';
tmp_value = zend_strtod(buf, NULL);
/* couldn't convert to string and back */
if (!zend_finite(tmp_value) || zend_isnan(tmp_value)) {
tmp_value = value;
}
}
return tmp_value;
}
示例11: is_numeric_string
DataType is_numeric_string(const char *str, int length, int64_t *lval,
double *dval, int allow_errors /* = 1 */) {
DataType type;
const char *ptr;
int base = 10, digits = 0, dp_or_e = 0;
double local_dval = 0.0;
if (!length || ((unsigned char)(*str)) > '9') {
return KindOfNull;
}
/* Skip any whitespace
* This is much faster than the isspace() function */
while (*str == ' ' ||
*str == '\t' ||
*str == '\n' ||
*str == '\r' ||
*str == '\v' ||
*str == '\f') {
str++;
length--;
}
ptr = str;
if (*ptr == '-' || *ptr == '+') {
ptr++;
}
if (IS_DIGIT(*ptr)) {
/* Handle hex numbers
* str is used instead of ptr to disallow signs and keep old behavior */
if (length > 2 && *str == '0' && (str[1] == 'x' || str[1] == 'X')) {
base = 16;
ptr += 2;
}
/* Skip any leading 0s */
while (*ptr == '0') {
ptr++;
}
/* Count the number of digits. If a decimal point/exponent is found,
* it's a double. Otherwise, if there's a dval or no need to check for
* a full match, stop when there are too many digits for a int64 */
for (type = KindOfInt64;
!(digits >= MAX_LENGTH_OF_LONG && (dval || allow_errors == 1));
digits++, ptr++) {
check_digits:
if (IS_DIGIT(*ptr) || (base == 16 && IS_XDIGIT(*ptr))) {
continue;
} else if (base == 10) {
if (*ptr == '.' && dp_or_e < 1) {
goto process_double;
} else if ((*ptr == 'e' || *ptr == 'E') && dp_or_e < 2) {
const char *e = ptr + 1;
if (*e == '-' || *e == '+') {
ptr = e++;
}
if (IS_DIGIT(*e)) {
goto process_double;
}
}
}
break;
}
if (base == 10) {
if (digits >= MAX_LENGTH_OF_LONG) {
dp_or_e = -1;
goto process_double;
}
} else if (!(digits < SIZEOF_LONG * 2 ||
(digits == SIZEOF_LONG * 2 && ptr[-digits] <= '7'))) {
if (dval) {
local_dval = zend_strtod(str, (char **)&ptr);
}
type = KindOfDouble;
}
} else if (*ptr == '.' && IS_DIGIT(ptr[1])) {
process_double:
type = KindOfDouble;
/* If there's a dval, do the conversion; else continue checking
* the digits if we need to check for a full match */
if (dval) {
local_dval = strtod(str, (char **)&ptr);
} else if (allow_errors != 1 && dp_or_e != -1) {
dp_or_e = (*ptr++ == '.') ? 1 : 2;
goto check_digits;
}
} else {
return KindOfNull;
}
if (ptr != str + length) {
if (!allow_errors) {
return KindOfNull;
}
//.........这里部分代码省略.........
示例12: php_sscanf_internal
//.........这里部分代码省略.........
}
break;
case '.':
if (flags & SCAN_PTOK) {
flags &= ~(SCAN_SIGNOK | SCAN_PTOK);
goto addToFloat;
}
break;
case 'e':
case 'E':
/*
* An exponent is not allowed until there has
* been at least one digit.
*/
if ((flags & (SCAN_NODIGITS | SCAN_EXPOK)) == SCAN_EXPOK) {
flags = (flags & ~(SCAN_EXPOK|SCAN_PTOK))
| SCAN_SIGNOK | SCAN_NODIGITS;
goto addToFloat;
}
break;
}
/*
* We got an illegal character so we are done accumulating.
*/
break;
addToFloat:
/*
* Add the character to the temporary buffer.
*/
*end++ = *string++;
if (*string == '\0') {
break;
}
}
/*
* Check to see if we need to back up because we saw a
* trailing 'e' or sign.
*/
if (flags & SCAN_NODIGITS) {
if (flags & SCAN_EXPOK) {
/*
* There were no digits at all so scanning has
* failed and we are done.
*/
if (*string == '\0') {
underflow = 1;
}
goto done;
}
/*
* We got a bad exponent ('e' and maybe a sign).
*/
end--;
string--;
if (*end != 'e' && *end != 'E') {
end--;
string--;
}
}
/*
* Scan the value from the temporary buffer.
*/
if (!(flags & SCAN_SUPPRESS)) {
double dvalue;
*end = '\0';
dvalue = zend_strtod(buf, NULL);
if (numVars && objIndex >= argCount) {
break;
} else if (numVars) {
current = Z_REFVAL(args[objIndex++]);
zval_ptr_dtor(current);
ZVAL_DOUBLE(current, dvalue);
} else {
add_index_double(return_value, objIndex++, dvalue );
}
}
break;
} /* switch (op) */
nconversions++;
} /* while (*format != '\0') */
done:
result = SCAN_SUCCESS;
if (underflow && (0==nconversions)) {
scan_set_error_return( numVars, return_value );
result = SCAN_ERROR_EOF;
} else if (numVars) {
convert_to_long(return_value );
Z_LVAL_P(return_value) = nconversions;
} else if (nconversions < totalVars) {
/* TODO: not all elements converted. we need to prune the list - cc */
}
return result;
}
示例13: ps_fetch_float
/* {{{ ps_fetch_float */
static void
ps_fetch_float(zval * zv, const MYSQLND_FIELD * const field, unsigned int pack_len, zend_uchar ** row)
{
float fval;
double dval;
DBG_ENTER("ps_fetch_float");
float4get(fval, *row);
(*row)+= 4;
DBG_INF_FMT("value=%f", fval);
/*
* The following is needed to correctly support 4-byte floats.
* Otherwise, a value of 9.99 in a FLOAT column comes out of mysqli
* as 9.9998998641968.
*
* For GCC, we use the built-in decimal support to "up-convert" a
* 4-byte float to a 8-byte double.
* When that is not available, we fall back to converting the float
* to a string and then converting the string to a double. This mimics
* what MySQL does.
*/
#ifdef HAVE_DECIMAL_FP_SUPPORT
{
typedef float dec32 __attribute__((mode(SD)));
dec32 d32val = fval;
/* The following cast is guaranteed to do the right thing */
dval = (double) d32val;
}
#elif defined(PHP_WIN32)
{
/* float datatype on Winows is already 4 byte but has a precision of 7 digits */
char num_buf[2048];
(void)_gcvt_s(num_buf, 2048, fval, field->decimals >= 31 ? 7 : field->decimals);
dval = zend_strtod(num_buf, NULL);
}
#else
{
char num_buf[2048]; /* Over allocated */
char *s;
#ifndef FLT_DIG
# define FLT_DIG 6
#endif
/* Convert to string. Ignoring localization, etc.
* Following MySQL's rules. If precision is undefined (NOT_FIXED_DEC i.e. 31)
* or larger than 31, the value is limited to 6 (FLT_DIG).
*/
s = php_gcvt(fval,
field->decimals >= 31 ? FLT_DIG : field->decimals,
'.',
'e',
num_buf);
/* And now convert back to double */
dval = zend_strtod(s, NULL);
}
#endif
ZVAL_DOUBLE(zv, dval);
DBG_VOID_RETURN;
}
示例14: ini_on_update
bool ini_on_update(const Variant& value, double& p) {
INI_ASSERT_STR(value);
p = zend_strtod(str.data(), nullptr);
return true;
}
示例15: ini_on_update
bool ini_on_update(const folly::dynamic& value, double& p) {
INI_ASSERT_STR(value);
p = zend_strtod(str.data(), nullptr);
return true;
}