summaryrefslogtreecommitdiff
path: root/Zend/zend_operators.c
diff options
context:
space:
mode:
authorAndi Gutmans <andi@php.net>2000-05-26 07:49:56 +0000
committerAndi Gutmans <andi@php.net>2000-05-26 07:49:56 +0000
commitb5447a4d7a91c0dea5f381a8ef4cde2ddb34a7f6 (patch)
treebb4359768955c1f84494ea65ffedbea1650bec4c /Zend/zend_operators.c
parentac309e969662975d84aca89fb77b10dbc7b4a507 (diff)
downloadphp-git-b5447a4d7a91c0dea5f381a8ef4cde2ddb34a7f6.tar.gz
- Fixed scanning decimal numbers in internationalized environments. They should
- always be in standard US format e.g. 23.3
Diffstat (limited to 'Zend/zend_operators.c')
-rw-r--r--Zend/zend_operators.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index 95b682ee1b..a058083ef8 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -49,6 +49,48 @@
#include "ext/bcmath/number.h"
#endif
+ZEND_API double zend_string_to_double(const char *number, zend_uint length)
+{
+ zend_uint i=0;
+ double divisor = 10.0;
+ double result = 0.0;
+ double exponent;
+
+ if (!length) {
+ return result;
+ }
+
+ for (i=0; i<length; i++) {
+ if ((number[i] <= '9' && number[i] >= '0')) {
+ result *= 10;
+ result += number[i] - '0';
+ } else if (number[i] == '.') {
+ i++;
+ break;
+ } else if (toupper(number[i]) == 'E') {
+ exponent = (double) atoi(&number[i+1]);
+ result *= pow(10.0, exponent);
+ return result;
+ } else {
+ return result;
+ }
+ }
+
+ for (; i<length; i++) {
+ if ((number[i] <= '9' && number[i] >= '0')) {
+ result += (number[i] - '0') / divisor;
+ divisor *= 10;
+ } else if (toupper(number[i]) == 'E') {
+ exponent = (double) atoi(&number[i+1]);
+ result *= pow(10.0, exponent);
+ return result;
+ } else {
+ return result;
+ }
+ }
+ return result;
+}
+
ZEND_API void convert_scalar_to_number(zval *op)
{