Add compiled C++ corpus (snappy, double-conversion, ninja x O0/O2/O2-noinline)
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +9 -0
- cpp-compiled/binaries/O0/double-conversion/libdouble-conversion.so.3.3.0 +3 -0
- cpp-compiled/binaries/O0/ninja/ninja +3 -0
- cpp-compiled/binaries/O0/snappy/libsnappy.so.1.2.2 +3 -0
- cpp-compiled/binaries/O2-noinline/double-conversion/libdouble-conversion.so.3.3.0 +3 -0
- cpp-compiled/binaries/O2-noinline/ninja/ninja +3 -0
- cpp-compiled/binaries/O2-noinline/snappy/libsnappy.so.1.2.2 +3 -0
- cpp-compiled/binaries/O2/double-conversion/libdouble-conversion.so.3.3.0 +3 -0
- cpp-compiled/binaries/O2/ninja/ninja +3 -0
- cpp-compiled/binaries/O2/snappy/libsnappy.so.1.2.2 +3 -0
- cpp-compiled/compile_report.json +101 -0
- cpp-compiled/manifest.json +333 -0
- cpp-compiled/sources/double-conversion/_variants/O2-noinline/bignum-dtoa.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2-noinline/bignum.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2-noinline/cached-powers.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2-noinline/double-to-string.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2-noinline/fast-dtoa.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2-noinline/fixed-dtoa.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2-noinline/string-to-double.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2-noinline/strtod.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2/bignum-dtoa.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2/bignum.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2/cached-powers.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2/double-to-string.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2/fast-dtoa.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2/fixed-dtoa.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2/string-to-double.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/_variants/O2/strtod.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/bignum-dtoa.cc +641 -0
- cpp-compiled/sources/double-conversion/bignum-dtoa.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/bignum.cc +797 -0
- cpp-compiled/sources/double-conversion/bignum.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/cached-powers.cc +175 -0
- cpp-compiled/sources/double-conversion/cached-powers.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/cctest.cc +144 -0
- cpp-compiled/sources/double-conversion/double-to-string.cc +447 -0
- cpp-compiled/sources/double-conversion/double-to-string.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/fast-dtoa.cc +665 -0
- cpp-compiled/sources/double-conversion/fast-dtoa.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/fixed-dtoa.cc +405 -0
- cpp-compiled/sources/double-conversion/fixed-dtoa.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/gay-fixed.cc +0 -0
- cpp-compiled/sources/double-conversion/gay-precision.cc +0 -0
- cpp-compiled/sources/double-conversion/gay-shortest-single.cc +0 -0
- cpp-compiled/sources/double-conversion/gay-shortest.cc +0 -0
- cpp-compiled/sources/double-conversion/string-to-double.cc +818 -0
- cpp-compiled/sources/double-conversion/string-to-double.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/strtod.cc +608 -0
- cpp-compiled/sources/double-conversion/strtod.cc.ii +0 -0
- cpp-compiled/sources/double-conversion/test-bignum-dtoa.cc +400 -0
.gitattributes
CHANGED
|
@@ -58,3 +58,12 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
cpp-compiled/binaries/O0/double-conversion/libdouble-conversion.so.3.3.0 filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
cpp-compiled/binaries/O0/ninja/ninja filter=lfs diff=lfs merge=lfs -text
|
| 63 |
+
cpp-compiled/binaries/O0/snappy/libsnappy.so.1.2.2 filter=lfs diff=lfs merge=lfs -text
|
| 64 |
+
cpp-compiled/binaries/O2/double-conversion/libdouble-conversion.so.3.3.0 filter=lfs diff=lfs merge=lfs -text
|
| 65 |
+
cpp-compiled/binaries/O2/ninja/ninja filter=lfs diff=lfs merge=lfs -text
|
| 66 |
+
cpp-compiled/binaries/O2/snappy/libsnappy.so.1.2.2 filter=lfs diff=lfs merge=lfs -text
|
| 67 |
+
cpp-compiled/binaries/O2-noinline/double-conversion/libdouble-conversion.so.3.3.0 filter=lfs diff=lfs merge=lfs -text
|
| 68 |
+
cpp-compiled/binaries/O2-noinline/ninja/ninja filter=lfs diff=lfs merge=lfs -text
|
| 69 |
+
cpp-compiled/binaries/O2-noinline/snappy/libsnappy.so.1.2.2 filter=lfs diff=lfs merge=lfs -text
|
cpp-compiled/binaries/O0/double-conversion/libdouble-conversion.so.3.3.0
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4e161e24d9a81d9d343f7018831ae87430c2704bb3b08b796904ef52aaae9813
|
| 3 |
+
size 404424
|
cpp-compiled/binaries/O0/ninja/ninja
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f7c2059f3a2674d95a7388d7d505883c062e33c301ffaa17dfba38e413ae9664
|
| 3 |
+
size 7266400
|
cpp-compiled/binaries/O0/snappy/libsnappy.so.1.2.2
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ef0fd26812f623cde46df205948ec2dc9a1ce11a8152ae3c7ac5ab06a9dda97f
|
| 3 |
+
size 850720
|
cpp-compiled/binaries/O2-noinline/double-conversion/libdouble-conversion.so.3.3.0
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:89a531a8e3208d17caceb8e3a2abf663566eebec694b9a83259a71899fb5ee39
|
| 3 |
+
size 510632
|
cpp-compiled/binaries/O2-noinline/ninja/ninja
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:63ef82d7b6ac58ebe9508b859c55a430d054c27f89cbe73b84d8f711e4801e9e
|
| 3 |
+
size 8103824
|
cpp-compiled/binaries/O2-noinline/snappy/libsnappy.so.1.2.2
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0a830c8706845c91352a8a7d312a42c32ca37bad5c883346a3bc5a8ef76abb0c
|
| 3 |
+
size 880568
|
cpp-compiled/binaries/O2/double-conversion/libdouble-conversion.so.3.3.0
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f0624060551b3a4b3ded1f285a9dfa97dea3f5349731fba8c04d965932810164
|
| 3 |
+
size 559464
|
cpp-compiled/binaries/O2/ninja/ninja
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b9b85b973c64ad70fbe1ed3b45336fdf5232015edc0b68ab5e96e556486f7c50
|
| 3 |
+
size 9645040
|
cpp-compiled/binaries/O2/snappy/libsnappy.so.1.2.2
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:21c68887f46e535a604d876a989b5a874067a102ea5fdf503d34bc45661f810d
|
| 3 |
+
size 817064
|
cpp-compiled/compile_report.json
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[
|
| 2 |
+
{
|
| 3 |
+
"project": "double-conversion",
|
| 4 |
+
"opt": "O0",
|
| 5 |
+
"linked_binaries": 1,
|
| 6 |
+
"i_files": 8,
|
| 7 |
+
"compile_results": 1,
|
| 8 |
+
"successes": 1,
|
| 9 |
+
"errors": [],
|
| 10 |
+
"seconds": 4.4,
|
| 11 |
+
"ok": true
|
| 12 |
+
},
|
| 13 |
+
{
|
| 14 |
+
"project": "double-conversion",
|
| 15 |
+
"opt": "O2",
|
| 16 |
+
"linked_binaries": 1,
|
| 17 |
+
"i_files": 8,
|
| 18 |
+
"compile_results": 1,
|
| 19 |
+
"successes": 1,
|
| 20 |
+
"errors": [],
|
| 21 |
+
"seconds": 5.3,
|
| 22 |
+
"ok": true
|
| 23 |
+
},
|
| 24 |
+
{
|
| 25 |
+
"project": "double-conversion",
|
| 26 |
+
"opt": "O2-noinline",
|
| 27 |
+
"linked_binaries": 1,
|
| 28 |
+
"i_files": 8,
|
| 29 |
+
"compile_results": 1,
|
| 30 |
+
"successes": 1,
|
| 31 |
+
"errors": [],
|
| 32 |
+
"seconds": 5.3,
|
| 33 |
+
"ok": true
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"project": "ninja",
|
| 37 |
+
"opt": "O0",
|
| 38 |
+
"linked_binaries": 1,
|
| 39 |
+
"i_files": 33,
|
| 40 |
+
"compile_results": 1,
|
| 41 |
+
"successes": 1,
|
| 42 |
+
"errors": [],
|
| 43 |
+
"seconds": 5.5,
|
| 44 |
+
"ok": true
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"project": "ninja",
|
| 48 |
+
"opt": "O2-noinline",
|
| 49 |
+
"linked_binaries": 1,
|
| 50 |
+
"i_files": 33,
|
| 51 |
+
"compile_results": 1,
|
| 52 |
+
"successes": 1,
|
| 53 |
+
"errors": [],
|
| 54 |
+
"seconds": 6.4,
|
| 55 |
+
"ok": true
|
| 56 |
+
},
|
| 57 |
+
{
|
| 58 |
+
"project": "ninja",
|
| 59 |
+
"opt": "O2",
|
| 60 |
+
"linked_binaries": 1,
|
| 61 |
+
"i_files": 33,
|
| 62 |
+
"compile_results": 1,
|
| 63 |
+
"successes": 1,
|
| 64 |
+
"errors": [],
|
| 65 |
+
"seconds": 6.6,
|
| 66 |
+
"ok": true
|
| 67 |
+
},
|
| 68 |
+
{
|
| 69 |
+
"project": "snappy",
|
| 70 |
+
"opt": "O0",
|
| 71 |
+
"linked_binaries": 1,
|
| 72 |
+
"i_files": 4,
|
| 73 |
+
"compile_results": 1,
|
| 74 |
+
"successes": 1,
|
| 75 |
+
"errors": [],
|
| 76 |
+
"seconds": 3.1,
|
| 77 |
+
"ok": true
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"project": "snappy",
|
| 81 |
+
"opt": "O2",
|
| 82 |
+
"linked_binaries": 1,
|
| 83 |
+
"i_files": 4,
|
| 84 |
+
"compile_results": 1,
|
| 85 |
+
"successes": 1,
|
| 86 |
+
"errors": [],
|
| 87 |
+
"seconds": 3.4,
|
| 88 |
+
"ok": true
|
| 89 |
+
},
|
| 90 |
+
{
|
| 91 |
+
"project": "snappy",
|
| 92 |
+
"opt": "O2-noinline",
|
| 93 |
+
"linked_binaries": 1,
|
| 94 |
+
"i_files": 4,
|
| 95 |
+
"compile_results": 1,
|
| 96 |
+
"successes": 1,
|
| 97 |
+
"errors": [],
|
| 98 |
+
"seconds": 3.4,
|
| 99 |
+
"ok": true
|
| 100 |
+
}
|
| 101 |
+
]
|
cpp-compiled/manifest.json
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"language": "c++",
|
| 3 |
+
"compiler": "GCC/G++ 13.3.0 (Ubuntu 24.04 aarch64)",
|
| 4 |
+
"ground_truth": "DWARF + preprocessed .ii",
|
| 5 |
+
"binaries": [
|
| 6 |
+
{
|
| 7 |
+
"path": "binaries/O0/double-conversion/libdouble-conversion.so.3.3.0",
|
| 8 |
+
"opt": "O0",
|
| 9 |
+
"project": "double-conversion",
|
| 10 |
+
"sha256": "4e161e24d9a81d9d343f7018831ae87430c2704bb3b08b796904ef52aaae9813",
|
| 11 |
+
"size": 404424,
|
| 12 |
+
"compile_ok": true
|
| 13 |
+
},
|
| 14 |
+
{
|
| 15 |
+
"path": "binaries/O0/ninja/ninja",
|
| 16 |
+
"opt": "O0",
|
| 17 |
+
"project": "ninja",
|
| 18 |
+
"sha256": "f7c2059f3a2674d95a7388d7d505883c062e33c301ffaa17dfba38e413ae9664",
|
| 19 |
+
"size": 7266400,
|
| 20 |
+
"compile_ok": true
|
| 21 |
+
},
|
| 22 |
+
{
|
| 23 |
+
"path": "binaries/O0/snappy/libsnappy.so.1.2.2",
|
| 24 |
+
"opt": "O0",
|
| 25 |
+
"project": "snappy",
|
| 26 |
+
"sha256": "ef0fd26812f623cde46df205948ec2dc9a1ce11a8152ae3c7ac5ab06a9dda97f",
|
| 27 |
+
"size": 850720,
|
| 28 |
+
"compile_ok": true
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"path": "binaries/O2/double-conversion/libdouble-conversion.so.3.3.0",
|
| 32 |
+
"opt": "O2",
|
| 33 |
+
"project": "double-conversion",
|
| 34 |
+
"sha256": "f0624060551b3a4b3ded1f285a9dfa97dea3f5349731fba8c04d965932810164",
|
| 35 |
+
"size": 559464,
|
| 36 |
+
"compile_ok": true
|
| 37 |
+
},
|
| 38 |
+
{
|
| 39 |
+
"path": "binaries/O2/ninja/ninja",
|
| 40 |
+
"opt": "O2",
|
| 41 |
+
"project": "ninja",
|
| 42 |
+
"sha256": "b9b85b973c64ad70fbe1ed3b45336fdf5232015edc0b68ab5e96e556486f7c50",
|
| 43 |
+
"size": 9645040,
|
| 44 |
+
"compile_ok": true
|
| 45 |
+
},
|
| 46 |
+
{
|
| 47 |
+
"path": "binaries/O2/snappy/libsnappy.so.1.2.2",
|
| 48 |
+
"opt": "O2",
|
| 49 |
+
"project": "snappy",
|
| 50 |
+
"sha256": "21c68887f46e535a604d876a989b5a874067a102ea5fdf503d34bc45661f810d",
|
| 51 |
+
"size": 817064,
|
| 52 |
+
"compile_ok": true
|
| 53 |
+
},
|
| 54 |
+
{
|
| 55 |
+
"path": "binaries/O2-noinline/double-conversion/libdouble-conversion.so.3.3.0",
|
| 56 |
+
"opt": "O2-noinline",
|
| 57 |
+
"project": "double-conversion",
|
| 58 |
+
"sha256": "89a531a8e3208d17caceb8e3a2abf663566eebec694b9a83259a71899fb5ee39",
|
| 59 |
+
"size": 510632,
|
| 60 |
+
"compile_ok": true
|
| 61 |
+
},
|
| 62 |
+
{
|
| 63 |
+
"path": "binaries/O2-noinline/ninja/ninja",
|
| 64 |
+
"opt": "O2-noinline",
|
| 65 |
+
"project": "ninja",
|
| 66 |
+
"sha256": "63ef82d7b6ac58ebe9508b859c55a430d054c27f89cbe73b84d8f711e4801e9e",
|
| 67 |
+
"size": 8103824,
|
| 68 |
+
"compile_ok": true
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"path": "binaries/O2-noinline/snappy/libsnappy.so.1.2.2",
|
| 72 |
+
"opt": "O2-noinline",
|
| 73 |
+
"project": "snappy",
|
| 74 |
+
"sha256": "0a830c8706845c91352a8a7d312a42c32ca37bad5c883346a3bc5a8ef76abb0c",
|
| 75 |
+
"size": 880568,
|
| 76 |
+
"compile_ok": true
|
| 77 |
+
}
|
| 78 |
+
],
|
| 79 |
+
"sources": {
|
| 80 |
+
"double-conversion": {
|
| 81 |
+
"bignum-dtoa.cc": "85a803ff5eaea5acc840182ab03dc1205b77519cb61d6615682314eb8aa90914",
|
| 82 |
+
"bignum-dtoa.cc.ii": "ff64aa86acb5104eefdb00631d02e084a69aebc86171bb2abcb92cf4efea0f8a",
|
| 83 |
+
"bignum.cc": "cc33c3775d66d138aa49ea5a18e73ad6766ecca17009225811c33cea64bcd11b",
|
| 84 |
+
"bignum.cc.ii": "b05b4619831b8242dbfcf1c1a623d4efdfdba4b3c42cb082381fa5cc9ed2d925",
|
| 85 |
+
"cached-powers.cc": "f0cabcc74f54ca33072671cc6c2819e39e8cd9b55db508946f2bd5acc1b48367",
|
| 86 |
+
"cached-powers.cc.ii": "f7fd92259bfb0c6e600e876a657d6b2f210e022bbe0f0d2f68dc7c430ddfa214",
|
| 87 |
+
"cctest.cc": "d311def3833586fc4ec7184a0ce252ead2ea0b53578295196a2f80acea9ab0e6",
|
| 88 |
+
"double-to-string.cc": "a74266a3b5b69e5c563023d6d01d54e0b09eb57656257c2dadee04648a8b931d",
|
| 89 |
+
"double-to-string.cc.ii": "e3993855a95748f410a36373e46d89b5fd40341a1f0c74e09e51978fd946e641",
|
| 90 |
+
"fast-dtoa.cc": "c2042b7bdd218435bcb4881a86a033bbd5dddbb6bd386a3a099247ca67882440",
|
| 91 |
+
"fast-dtoa.cc.ii": "69e61af2b6efeb406761b9d630d79c9d952dadb10eeb1a2facf2a2f852dfe555",
|
| 92 |
+
"fixed-dtoa.cc": "6cbef46bd0f6a482f4c79e34d14e49b448094d85bcefc25177957d84b62b2144",
|
| 93 |
+
"fixed-dtoa.cc.ii": "c90343e8a1c270dccb8487ed20d2cba15cbc83a0726fb83299ef1b1f15a0b029",
|
| 94 |
+
"gay-fixed.cc": "91844fee493ab175eafefaee377bce822d3c0c078364f40988ef72f4231752cb",
|
| 95 |
+
"gay-precision.cc": "3db681fe4a8456078ff5b5181e05386fbf26089323dc0ef249616f2311a10be7",
|
| 96 |
+
"gay-shortest-single.cc": "1a4e3369e2a20bcb159c044cc2038dacf6d43aca41de333a9b7d1bd54ce72013",
|
| 97 |
+
"gay-shortest.cc": "0e6777926eceb0221d6985bfd7405b99bf2423be2b248093f22fc25eecaaae59",
|
| 98 |
+
"string-to-double.cc": "9aafd7e77a23164ee94903cfd16bd1e84344a5d7a18b4ee430e35e76568b108d",
|
| 99 |
+
"string-to-double.cc.ii": "9445e3426f00d068792c5855a4fb32e5b64e79aca70f1ea159edcefa6715da01",
|
| 100 |
+
"strtod.cc": "923f15ce6bff38b9aaa1f3bced157c468978ac9443fbb781f0826daeae5cd4ee",
|
| 101 |
+
"strtod.cc.ii": "93dacf367648c44af45700b0f2148102ebbc2f8a743484c28fd2ff668f8ea454",
|
| 102 |
+
"test-bignum-dtoa.cc": "b36afb11cb5b3dcf6db292ea2543a77f4ff9d971418869cd918d0941729b6554",
|
| 103 |
+
"test-bignum.cc": "e4ad67132651ae4cb0aab57a358b305bdf18542db7820685e59ccf560c53f87e",
|
| 104 |
+
"test-conversions.cc": "9ede04a0862e6534acfb2a6cb078bf35e1f4688f6acee032703cd3b5e2082210",
|
| 105 |
+
"test-diy-fp.cc": "6b5aaddbe9b5da9d4b2ccc61b18d99aab51568e510d59f71db024ab8f30b60e7",
|
| 106 |
+
"test-dtoa.cc": "d66d32627d559e54615f4ac8744515628368da57247c1c6abfec5106abaca760",
|
| 107 |
+
"test-fast-dtoa.cc": "4526a162e94667f26e9a3d184ae002c6f580f73f04214dc69afdd0d809844feb",
|
| 108 |
+
"test-fixed-dtoa.cc": "c030fb2a45516f322c4b11c43e9ded554c225dbc0794c60d8dee0f0a9594d803",
|
| 109 |
+
"test-ieee.cc": "3cd28a9bda824e686649181861dd4d6b75e04cc7c352dd9c6c28124783caa48f",
|
| 110 |
+
"test-strtod.cc": "3a0623b076cccec0663ae34ccb681f33e6249d82730f7d55296b6aaeca3e1962"
|
| 111 |
+
},
|
| 112 |
+
"ninja": {
|
| 113 |
+
"browse.cc": "c626cb4e22350fffcda2723451e7ee85cb8705c90723ea0f7d214db12915dadd",
|
| 114 |
+
"browse.cc.ii": "afa16766a303f8d58770e9a69f10b189ce1530ca6bd05cf7b3bc9829005c4ef4",
|
| 115 |
+
"build.cc": "afd4ececbb6462ff55aa67414dca9963d069bed338e7855548e6527f427544ae",
|
| 116 |
+
"build.cc.ii": "208cfdec845b2e923c4a10174278c9073abfee0359f70c624a3422d13a4dd142",
|
| 117 |
+
"build_log.cc": "378d1fd92e9b44a6ee8b34bc83c6220ea3d702b9a7d215307ed7c1874bb8e7c6",
|
| 118 |
+
"build_log.cc.ii": "907b1d1bb60c327a72814d2e945eef9459d124e5481d6293ddeedbd1a4b93b6e",
|
| 119 |
+
"build_log_perftest.cc": "640b3bbcddc0216cd8873cd10509fddf9fe18e339831d32655757f62d68e9430",
|
| 120 |
+
"build_log_test.cc": "a705e179c7e4f6fa54456f4e9b19a6fd3ede3feb489f04f74dc2e429e2f8027e",
|
| 121 |
+
"build_test.cc": "ddc12c4c251540745281c4ef1bfb1dad26f4ee4afef58551bbaae7c382f600cc",
|
| 122 |
+
"canon_perftest.cc": "eb350509bb6173818d22700bed689771db2f065cb4632422c8c705814e20b3a9",
|
| 123 |
+
"clean.cc": "b833b3275474655ce30e7d6e33a53f2a002f9c09e9ed11eafc5492354087d6ef",
|
| 124 |
+
"clean.cc.ii": "89d48f3e658432cdf393f4d8eda4b418b15567ebcf15e66507738a170ca1b956",
|
| 125 |
+
"clean_test.cc": "0cfe4a180bc763e1aaf2e67dd11346ebbc3fcadc800c94e1b242202fce19adc0",
|
| 126 |
+
"clparser.cc": "9d758a927372e28ec63b3921e30e6c2107220bcb53b601dd5f1af56a7d34c89a",
|
| 127 |
+
"clparser.cc.ii": "f3d8d7af1cafa4505960381c8dc7d0b79dcafd8781ce60e7b0c0354c3f6ff372",
|
| 128 |
+
"clparser_perftest.cc": "49285c180b3d1b640c31ab9f870b76c66b35a0b616763e2f1e50953e9dabe9e8",
|
| 129 |
+
"clparser_test.cc": "a5011462b7ca189cb7656a6d80f24e5a1d5dfad2744be5642480ed6d07f09434",
|
| 130 |
+
"debug_flags.cc": "8fad28f2dd7993d30063dc6916620ac18eb9d2f9d01d921aa9d57b6b0aaa8e53",
|
| 131 |
+
"debug_flags.cc.ii": "e50f7f4e88f019d980d9cf07be5e546922738476931d27cf808dd0b74504e8f5",
|
| 132 |
+
"depfile_parser.cc": "ec38bf63111f827ace793226b32bea7c87436619ca0d7603ce6011b41732b417",
|
| 133 |
+
"depfile_parser.cc.ii": "2094e57e3be2525fb7f238efbeea8e279f554d04e12d807f87518b290ed0790b",
|
| 134 |
+
"depfile_parser.in.cc": "0564b48a9f1b7f61e5688fc162a656d31b99894e170ad2a3c85e12e9ac6db506",
|
| 135 |
+
"depfile_parser_perftest.cc": "a6b36a5fb404774ae7f5341624a56375c363f134845d6e320d757c907e48feaf",
|
| 136 |
+
"depfile_parser_test.cc": "9b481ec75ec2f019e54910e0dd5f612bf1f6445f49780983f9887edce901f06f",
|
| 137 |
+
"deps_log.cc": "2082de317ab4e987c4b3d4a5017225d1a779b27f50bf9484087a22ee6cf764fd",
|
| 138 |
+
"deps_log.cc.ii": "223187591c8cae5521555684ccb8f54df8577d03d696ea0552102204773fde03",
|
| 139 |
+
"deps_log_test.cc": "a6e2177eca5c44ee5db7a94f1ba2b30fe805fb89007b6324a847f4682086dff6",
|
| 140 |
+
"disk_interface.cc": "3abb519615b6c9744ad028684e9797a2abf82f722bc58025d98e83355279644e",
|
| 141 |
+
"disk_interface.cc.ii": "f2e84eacc18598831d089403ed5de057e17d624512c176dfdd1d0d13ba2c6117",
|
| 142 |
+
"disk_interface_test.cc": "7dde4141cf0344f0a79508e3fc67e0ed394a64f8b292a6d1b713b84d72220c9f",
|
| 143 |
+
"dyndep.cc": "443ef071047e32035e098d84ff5423b694c9672b5e5361fe31290e2b88a0b6c6",
|
| 144 |
+
"dyndep.cc.ii": "9d1a291cda19608d8decc2eda98c9dacbe5aa1aa97afe69cdfa963459f423115",
|
| 145 |
+
"dyndep_parser.cc": "79244f51c25d9bbfd55448305861553f1de9afb0a5a2dbafc51a2cc939136130",
|
| 146 |
+
"dyndep_parser.cc.ii": "8898b3bc2be71d6572d9f3a5a9d7e83984ad1f6e372d368b8ec0a73e28e87e26",
|
| 147 |
+
"dyndep_parser_test.cc": "0adf8c6dc89eae5c9bf5580c75610d6c35aa71da45e36e175a1c8e9dcf239f65",
|
| 148 |
+
"edit_distance.cc": "1188176a4a180141cf55ebcce7ed4fa20b3507a4fd93225fc8143324e3d9c1b6",
|
| 149 |
+
"edit_distance.cc.ii": "5e19d9d592d3f55fcfa3ac9c5d97cb8bca8e487b479346acce5c129c133b1192",
|
| 150 |
+
"edit_distance_test.cc": "fc16ea891a66797e3d7075117acba0092a1ce94ff59ee5a73032632fc477ef92",
|
| 151 |
+
"elide_middle.cc": "944ec06eda4375bee90b161b7854c4476f7108a1a6292b97120a11daad386fab",
|
| 152 |
+
"elide_middle.cc.ii": "7296baff26bb209735149a258b192f896e4d63a252f1de39121f00454be1b728",
|
| 153 |
+
"elide_middle_perftest.cc": "f592eff3a19ea633c6f24d8656a0a7c20dff744ffd2e1998f1b63c9cbca3eff3",
|
| 154 |
+
"elide_middle_test.cc": "5d5679342b23ee07173c6e358c2cde439d78c8b8477e7d32525c7925d605f45b",
|
| 155 |
+
"eval_env.cc": "8a6c4227983e889be66a847b0451b8f6ff5bde271e1f200b6597b8b046b78940",
|
| 156 |
+
"eval_env.cc.ii": "7eea673059e5ae4c5c28d146354e40e75b3dabdf08d237acb043ac8b2e73398a",
|
| 157 |
+
"explanations_test.cc": "811a87be2850225b942944c39dd17662450814e9c55bdf5b169fe7efd8bf020a",
|
| 158 |
+
"getopt.c": "a0e40f26252d08a127b7c6fb16499447c543252f883154322207fa8b1d8d460a",
|
| 159 |
+
"graph.cc": "cc0f3578325e77600c2979bccce28f9139cf38f333d51c5f5fc8b57809413e37",
|
| 160 |
+
"graph.cc.ii": "95175750e7531b6161d9ac3c9073d9133498b66523a6cce22b07d08f9b3aa970",
|
| 161 |
+
"graph_test.cc": "b1dc13cede15fcd67a8ed6a05a6976ffd743a6aa2512661b0b0af627bae841ee",
|
| 162 |
+
"graphviz.cc": "8bd20be6f365647860d84bede96a5629b94b3cd603f726de3772c27adb96cbd6",
|
| 163 |
+
"graphviz.cc.ii": "ee92a852586dd97a4102da97d5001e9a53803f9a90c5247c0ed294188e02ef9e",
|
| 164 |
+
"hash_collision_bench.cc": "e7cc2f803713c6147930ce61f5a4c899d7e7cfaa9ed60fa1681dcdd9a9433db9",
|
| 165 |
+
"includes_normalize-win32.cc": "f6df9a471e05ca22793981ba046e58f9531ed6015d950626d96bbfebbd2dff6a",
|
| 166 |
+
"includes_normalize_test.cc": "3d5c3da3be0748b4cd2850bfcadae6bb73f77b0d5054398c05c41c2780286307",
|
| 167 |
+
"jobserver-posix.cc": "fee3b0c611c1679b320ed8fc36fcb627615ba1c1daef2858b3e761d9f2929c51",
|
| 168 |
+
"jobserver-posix.cc.ii": "c336cf2985d7b332fa053c44ea085876f85c639edfe3fbaf04d23a7c7f5ee4a4",
|
| 169 |
+
"jobserver-win32.cc": "eca87071f381bced982261456827f138375be39ee93aebb7af1647fa1fd98e7b",
|
| 170 |
+
"jobserver.cc": "f339af72963ee72c2ed7a7e6b88b782a652dadaf22cb1f014b8676e90893d20b",
|
| 171 |
+
"jobserver.cc.ii": "ac0c74c253c9dd6fc6c2d36f273a8c04b654b8f3155d9d8fad71f7c531ca3fa7",
|
| 172 |
+
"jobserver_test.cc": "665ab8ac6bd49c222c35f6af96a492b38f55c75ec2497331b535008869a20a17",
|
| 173 |
+
"json.cc": "12f6e9e1d49868a31a7d66d90e40978005471c95564d77e8cb34ab4c97eb3ff6",
|
| 174 |
+
"json.cc.ii": "95e03a54e0436a3de8cca51b176fb7f30803268388bf3a9cde88a055a4ceaacb",
|
| 175 |
+
"json_test.cc": "df3b891b24b37c5521ee48550d6336df9f04f245c24113cc3f855ee508a35fa8",
|
| 176 |
+
"lexer.cc": "fbdb828487f63f4a7d9184d2b71ea0f517b749c4450092f711baa5ae58a8991b",
|
| 177 |
+
"lexer.cc.ii": "5ec0846c397f858203fc94dce03ff41210e439ac6819052483f4cbc5d1595d8a",
|
| 178 |
+
"lexer.in.cc": "c6f41eba7f1cfcef242e50f2d10a88bdb7b9a0696cdd131d2b9ba7f4f565e216",
|
| 179 |
+
"lexer_test.cc": "64c90a489b1d778f70abfa7584e605e950638de07b7627da978f7d9837972e07",
|
| 180 |
+
"line_printer.cc": "823fd0eeed402aad5bf9d2c4f3f37cdc9bf02936e96f343d8bbc5c861dae7e41",
|
| 181 |
+
"line_printer.cc.ii": "4eeb48979655e0d0bd652aaa53d249cfc1375b69c25deab40c0b51add133f2c3",
|
| 182 |
+
"manifest_fuzzer.cc": "07ec328cadd1819bfe5c9feb0c1b47b93677ff26c6c3233886aa8d919bfdfcbf",
|
| 183 |
+
"manifest_parser.cc": "bf283240bfdf315366dbca5296d8ad1f2f32ce7a80fdbd4201713eab88c3cd97",
|
| 184 |
+
"manifest_parser.cc.ii": "ded5667c6270611d851db3720b25310d7ec9c5343f2416bf4fde26df4cfb1516",
|
| 185 |
+
"manifest_parser_perftest.cc": "ff9cd76e7585f94257cc10a5092ed03531ef542aef0bfb0420055b5b807d29c0",
|
| 186 |
+
"manifest_parser_test.cc": "fc350726841ffe4b05d5e0dad9950099b9080578cd1be861e4eed7fdc03e86c4",
|
| 187 |
+
"metrics.cc": "75f45539033dfd19bfc6f46894a562a98ab5958e9169c373babf7949ff1542f2",
|
| 188 |
+
"metrics.cc.ii": "7afdf904f96500b8c0043107d79ae963c6c871a51f4c32a8c935ff2f9d48bee0",
|
| 189 |
+
"minidump-win32.cc": "72c085c7bf9cb5d951509b19cdf112004fa3fac75a23a55868989daba3b58608",
|
| 190 |
+
"missing_deps.cc": "c7abb23fdf26ba7a33750fe58f0a9801e5edba14935d2986b15e079aaff04c67",
|
| 191 |
+
"missing_deps.cc.ii": "129058003b4d1c11529b3cd1abeda5fb9aaa6b27532db1f5eda9b7a3ea6c2785",
|
| 192 |
+
"missing_deps_test.cc": "e1587d32126b38b6a25f0345065ca42f44e0596e316099eb15af094bc8840db1",
|
| 193 |
+
"msvc_helper-win32.cc": "33efb0c698b1de4c5fc5b282e2e59b2c085be283278e9c7ca8d3df85c2425aac",
|
| 194 |
+
"msvc_helper_main-win32.cc": "4337dadad050e1e0fafb57fb6456f6fb356f27c44af12ca3a61d02366bc6a59a",
|
| 195 |
+
"msvc_helper_test.cc": "0862d27abe0c9cbb6e9c139f8d92648a111f1a0233c98766a0077572130d042a",
|
| 196 |
+
"ninja.cc": "9d671f4d44eb06a548bbd97adbc9af33e49d72ef2a9ee11fb6aa59f681ab02c8",
|
| 197 |
+
"ninja.cc.ii": "62557ba8cd72c22e23f7b5c2d649b6f203874a0a842abf6d63518bd91fcb44dc",
|
| 198 |
+
"ninja_test.cc": "7aa839982936364dad2c617f680a1fa7faab756aff9a2c5f2d240d70c9fe676d",
|
| 199 |
+
"parser.cc": "cb852cf39db05a055f6c37ed7fa1da10af46b84e4602770ab6c60b76b607331d",
|
| 200 |
+
"parser.cc.ii": "81f547b22b9352bfdd28575b1129ab27c254ca87a9862c01772d3310e57e6f05",
|
| 201 |
+
"real_command_runner.cc": "c45610e2bfcbcf655184e7e94b2f5e33550e80f12aa072e1bdf7c0a085f74947",
|
| 202 |
+
"real_command_runner.cc.ii": "a72e563c2b036b22f891ab58721c6d4352a7488c018a7c55d672e9b3181719c6",
|
| 203 |
+
"state.cc": "413155e79563ae114d8bd08ae46552c6201b529a5ecf881edbe3ccb0148c3f06",
|
| 204 |
+
"state.cc.ii": "297e036074ac9d7b4748fcb0d2c11e76bee03150c4546bc87f3085e0ae9e0973",
|
| 205 |
+
"state_test.cc": "247d592e2cddeab97e715fb7120b03e8c0a48cdcd8504a9ac3ee44b10a5d0d30",
|
| 206 |
+
"status_printer.cc": "524d2eeef040c22ce65278649f8f06542125596063fec034cc883d5b620faf66",
|
| 207 |
+
"status_printer.cc.ii": "5f991264f06cd0bc2efbbc53fa62b33a796461536cfdebfb6c5b53b2031f7a83",
|
| 208 |
+
"status_test.cc": "4d7d784f5d765f2e94732cd6c583f70fc681f5bafe10eb4ba9abe1b2bb2e6bff",
|
| 209 |
+
"string_piece_util.cc": "935fabb62c6255a4fbe8981afa444990fdbffd88b7d2824d2bb2a4c5e0f2b05f",
|
| 210 |
+
"string_piece_util.cc.ii": "16882c8d7d7a6892ddf2354cda043e6db76f52552b75c65c9d2296ae97a6280c",
|
| 211 |
+
"string_piece_util_test.cc": "a670cbb13a07bd8222a2bf0feea3d1f1fe73ecf0156ad141333fda2f5d0be0de",
|
| 212 |
+
"subprocess-posix.cc": "a9a4ea4280ac4e9e3d275dc4458c30baf0c067c8cd51b3c6d2034fe6eab88fdc",
|
| 213 |
+
"subprocess-posix.cc.ii": "d78cf7935409122e93653421345db53b49ce89d61c188a24b84fb71a487c61d6",
|
| 214 |
+
"subprocess-win32.cc": "2ebc7c0606625e4a84359c0e9a0a763feb77f3d18c0787b03cf1a8e641515f81",
|
| 215 |
+
"subprocess_test.cc": "f4eec807c9f67bae5670d873d21db1cfb725af57114c9cc79c27da73bde8101e",
|
| 216 |
+
"test.cc": "a65e4e42596691bf10540c5a7d1ee10148627ba3021ddd757da8ec6125e40c5f",
|
| 217 |
+
"util.cc": "bdb91b207eba44bcc1086dd30a08339959a1c2dad39bd4efb8e168290e036a33",
|
| 218 |
+
"util.cc.ii": "78976e7e3798a4931d20ceb2c7e5a1aa7e113cacb9de4be04070bcdbebba02c1",
|
| 219 |
+
"util_test.cc": "87874465a30d60a4311e394d5c40f13baa7717282f295daa81b02fecb80b4611",
|
| 220 |
+
"version.cc": "99ebcc09e62f9fd9161e736a4ab3db714dc990146ed449f22e1878c10fb700af",
|
| 221 |
+
"version.cc.ii": "8188afdf3761b44668827418348c9fe3baece3d7ffdfcc17a9e601cf9637ee9a"
|
| 222 |
+
},
|
| 223 |
+
"snappy": {
|
| 224 |
+
"snappy-c.cc": "bd06ca0e8243940aaee6c42cf13aa212870b9b1b7d036727fc636f02c37e797d",
|
| 225 |
+
"snappy-c.cc.ii": "dec7163fb76f5d82f702ffe42151dc92728d0a03d7c60d8bb291e3c7db669eec",
|
| 226 |
+
"snappy-sinksource.cc": "52c609f0fa9bea1dbb5dd1151b2536ee849b3e1e7fdb1380de8b08c4c74b748f",
|
| 227 |
+
"snappy-sinksource.cc.ii": "e0038a60a8bc3584c24aac15b2e80906bd9c846f210cf0c3c8af684ff13ed051",
|
| 228 |
+
"snappy-stubs-internal.cc": "3652c4fe3d8606f6a444af65bd9e0521290dac17a8889d19aaa9f8c212978a24",
|
| 229 |
+
"snappy-stubs-internal.cc.ii": "32336a857101535807c9eaea2eca27a86393ff2047a5f2ea993e05ef94f4865a",
|
| 230 |
+
"snappy-test.cc": "03a53acee2cdf298e416b073053361ea4a884c2f8da9f84f4fd8b31738fc2df7",
|
| 231 |
+
"snappy.cc": "614766218acd35f7cee9f2e91b56a0890cb218045044ebf026010ffc883cf344",
|
| 232 |
+
"snappy.cc.ii": "ef2fe8b5a911c6099613a0a140437345856b2f62f4a84fb13381f4325d58c7db",
|
| 233 |
+
"snappy_benchmark.cc": "ba51d966c9ba4068c18c3330c5f0e0368be55f20515d4d0cc67174605531cade",
|
| 234 |
+
"snappy_compress_fuzzer.cc": "44b20d9da6191800eddb78bb4892688dc6cdbbfde7d92662462d3695ff4280f5",
|
| 235 |
+
"snappy_test_data.cc": "6111a0f08d20c6fb6a2a144b94cdc87e025c6644eb46569d93f3c552c9a7155c",
|
| 236 |
+
"snappy_test_tool.cc": "1914554a346f85e7ced936cb27ac4affe1f640b53b2cdbe532c579a112760f53",
|
| 237 |
+
"snappy_uncompress_fuzzer.cc": "a8924f34a4bf5f38b6b387c02d042686bdc5b52fed53de6c3f2b5c057180d114",
|
| 238 |
+
"snappy_unittest.cc": "dd568b8ff6cad7ba7d64828cd527377c9236bace69fbec4ee600715495090ae1"
|
| 239 |
+
}
|
| 240 |
+
},
|
| 241 |
+
"source_variants": [
|
| 242 |
+
"sources/double-conversion/_variants/O2/bignum-dtoa.cc.ii",
|
| 243 |
+
"sources/double-conversion/_variants/O2/bignum.cc.ii",
|
| 244 |
+
"sources/double-conversion/_variants/O2/cached-powers.cc.ii",
|
| 245 |
+
"sources/double-conversion/_variants/O2/double-to-string.cc.ii",
|
| 246 |
+
"sources/double-conversion/_variants/O2/fast-dtoa.cc.ii",
|
| 247 |
+
"sources/double-conversion/_variants/O2/fixed-dtoa.cc.ii",
|
| 248 |
+
"sources/double-conversion/_variants/O2/string-to-double.cc.ii",
|
| 249 |
+
"sources/double-conversion/_variants/O2/strtod.cc.ii",
|
| 250 |
+
"sources/ninja/_variants/O2/browse.cc.ii",
|
| 251 |
+
"sources/ninja/_variants/O2/build.cc.ii",
|
| 252 |
+
"sources/ninja/_variants/O2/build_log.cc.ii",
|
| 253 |
+
"sources/ninja/_variants/O2/clean.cc.ii",
|
| 254 |
+
"sources/ninja/_variants/O2/clparser.cc.ii",
|
| 255 |
+
"sources/ninja/_variants/O2/debug_flags.cc.ii",
|
| 256 |
+
"sources/ninja/_variants/O2/depfile_parser.cc.ii",
|
| 257 |
+
"sources/ninja/_variants/O2/deps_log.cc.ii",
|
| 258 |
+
"sources/ninja/_variants/O2/disk_interface.cc.ii",
|
| 259 |
+
"sources/ninja/_variants/O2/dyndep.cc.ii",
|
| 260 |
+
"sources/ninja/_variants/O2/dyndep_parser.cc.ii",
|
| 261 |
+
"sources/ninja/_variants/O2/edit_distance.cc.ii",
|
| 262 |
+
"sources/ninja/_variants/O2/elide_middle.cc.ii",
|
| 263 |
+
"sources/ninja/_variants/O2/eval_env.cc.ii",
|
| 264 |
+
"sources/ninja/_variants/O2/graph.cc.ii",
|
| 265 |
+
"sources/ninja/_variants/O2/graphviz.cc.ii",
|
| 266 |
+
"sources/ninja/_variants/O2/jobserver-posix.cc.ii",
|
| 267 |
+
"sources/ninja/_variants/O2/jobserver.cc.ii",
|
| 268 |
+
"sources/ninja/_variants/O2/json.cc.ii",
|
| 269 |
+
"sources/ninja/_variants/O2/lexer.cc.ii",
|
| 270 |
+
"sources/ninja/_variants/O2/line_printer.cc.ii",
|
| 271 |
+
"sources/ninja/_variants/O2/manifest_parser.cc.ii",
|
| 272 |
+
"sources/ninja/_variants/O2/metrics.cc.ii",
|
| 273 |
+
"sources/ninja/_variants/O2/missing_deps.cc.ii",
|
| 274 |
+
"sources/ninja/_variants/O2/ninja.cc.ii",
|
| 275 |
+
"sources/ninja/_variants/O2/parser.cc.ii",
|
| 276 |
+
"sources/ninja/_variants/O2/real_command_runner.cc.ii",
|
| 277 |
+
"sources/ninja/_variants/O2/state.cc.ii",
|
| 278 |
+
"sources/ninja/_variants/O2/status_printer.cc.ii",
|
| 279 |
+
"sources/ninja/_variants/O2/string_piece_util.cc.ii",
|
| 280 |
+
"sources/ninja/_variants/O2/subprocess-posix.cc.ii",
|
| 281 |
+
"sources/ninja/_variants/O2/util.cc.ii",
|
| 282 |
+
"sources/ninja/_variants/O2/version.cc.ii",
|
| 283 |
+
"sources/snappy/_variants/O2/snappy-c.cc.ii",
|
| 284 |
+
"sources/snappy/_variants/O2/snappy-sinksource.cc.ii",
|
| 285 |
+
"sources/snappy/_variants/O2/snappy-stubs-internal.cc.ii",
|
| 286 |
+
"sources/snappy/_variants/O2/snappy.cc.ii",
|
| 287 |
+
"sources/double-conversion/_variants/O2-noinline/bignum-dtoa.cc.ii",
|
| 288 |
+
"sources/double-conversion/_variants/O2-noinline/bignum.cc.ii",
|
| 289 |
+
"sources/double-conversion/_variants/O2-noinline/cached-powers.cc.ii",
|
| 290 |
+
"sources/double-conversion/_variants/O2-noinline/double-to-string.cc.ii",
|
| 291 |
+
"sources/double-conversion/_variants/O2-noinline/fast-dtoa.cc.ii",
|
| 292 |
+
"sources/double-conversion/_variants/O2-noinline/fixed-dtoa.cc.ii",
|
| 293 |
+
"sources/double-conversion/_variants/O2-noinline/string-to-double.cc.ii",
|
| 294 |
+
"sources/double-conversion/_variants/O2-noinline/strtod.cc.ii",
|
| 295 |
+
"sources/ninja/_variants/O2-noinline/browse.cc.ii",
|
| 296 |
+
"sources/ninja/_variants/O2-noinline/build.cc.ii",
|
| 297 |
+
"sources/ninja/_variants/O2-noinline/build_log.cc.ii",
|
| 298 |
+
"sources/ninja/_variants/O2-noinline/clean.cc.ii",
|
| 299 |
+
"sources/ninja/_variants/O2-noinline/clparser.cc.ii",
|
| 300 |
+
"sources/ninja/_variants/O2-noinline/debug_flags.cc.ii",
|
| 301 |
+
"sources/ninja/_variants/O2-noinline/depfile_parser.cc.ii",
|
| 302 |
+
"sources/ninja/_variants/O2-noinline/deps_log.cc.ii",
|
| 303 |
+
"sources/ninja/_variants/O2-noinline/disk_interface.cc.ii",
|
| 304 |
+
"sources/ninja/_variants/O2-noinline/dyndep.cc.ii",
|
| 305 |
+
"sources/ninja/_variants/O2-noinline/dyndep_parser.cc.ii",
|
| 306 |
+
"sources/ninja/_variants/O2-noinline/edit_distance.cc.ii",
|
| 307 |
+
"sources/ninja/_variants/O2-noinline/elide_middle.cc.ii",
|
| 308 |
+
"sources/ninja/_variants/O2-noinline/eval_env.cc.ii",
|
| 309 |
+
"sources/ninja/_variants/O2-noinline/graph.cc.ii",
|
| 310 |
+
"sources/ninja/_variants/O2-noinline/graphviz.cc.ii",
|
| 311 |
+
"sources/ninja/_variants/O2-noinline/jobserver-posix.cc.ii",
|
| 312 |
+
"sources/ninja/_variants/O2-noinline/jobserver.cc.ii",
|
| 313 |
+
"sources/ninja/_variants/O2-noinline/json.cc.ii",
|
| 314 |
+
"sources/ninja/_variants/O2-noinline/lexer.cc.ii",
|
| 315 |
+
"sources/ninja/_variants/O2-noinline/line_printer.cc.ii",
|
| 316 |
+
"sources/ninja/_variants/O2-noinline/manifest_parser.cc.ii",
|
| 317 |
+
"sources/ninja/_variants/O2-noinline/metrics.cc.ii",
|
| 318 |
+
"sources/ninja/_variants/O2-noinline/missing_deps.cc.ii",
|
| 319 |
+
"sources/ninja/_variants/O2-noinline/ninja.cc.ii",
|
| 320 |
+
"sources/ninja/_variants/O2-noinline/parser.cc.ii",
|
| 321 |
+
"sources/ninja/_variants/O2-noinline/real_command_runner.cc.ii",
|
| 322 |
+
"sources/ninja/_variants/O2-noinline/state.cc.ii",
|
| 323 |
+
"sources/ninja/_variants/O2-noinline/status_printer.cc.ii",
|
| 324 |
+
"sources/ninja/_variants/O2-noinline/string_piece_util.cc.ii",
|
| 325 |
+
"sources/ninja/_variants/O2-noinline/subprocess-posix.cc.ii",
|
| 326 |
+
"sources/ninja/_variants/O2-noinline/util.cc.ii",
|
| 327 |
+
"sources/ninja/_variants/O2-noinline/version.cc.ii",
|
| 328 |
+
"sources/snappy/_variants/O2-noinline/snappy-c.cc.ii",
|
| 329 |
+
"sources/snappy/_variants/O2-noinline/snappy-sinksource.cc.ii",
|
| 330 |
+
"sources/snappy/_variants/O2-noinline/snappy-stubs-internal.cc.ii",
|
| 331 |
+
"sources/snappy/_variants/O2-noinline/snappy.cc.ii"
|
| 332 |
+
]
|
| 333 |
+
}
|
cpp-compiled/sources/double-conversion/_variants/O2-noinline/bignum-dtoa.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2-noinline/bignum.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2-noinline/cached-powers.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2-noinline/double-to-string.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2-noinline/fast-dtoa.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2-noinline/fixed-dtoa.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2-noinline/string-to-double.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2-noinline/strtod.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2/bignum-dtoa.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2/bignum.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2/cached-powers.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2/double-to-string.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2/fast-dtoa.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2/fixed-dtoa.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2/string-to-double.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/_variants/O2/strtod.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/bignum-dtoa.cc
ADDED
|
@@ -0,0 +1,641 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2010 the V8 project authors. All rights reserved.
|
| 2 |
+
// Redistribution and use in source and binary forms, with or without
|
| 3 |
+
// modification, are permitted provided that the following conditions are
|
| 4 |
+
// met:
|
| 5 |
+
//
|
| 6 |
+
// * Redistributions of source code must retain the above copyright
|
| 7 |
+
// notice, this list of conditions and the following disclaimer.
|
| 8 |
+
// * Redistributions in binary form must reproduce the above
|
| 9 |
+
// copyright notice, this list of conditions and the following
|
| 10 |
+
// disclaimer in the documentation and/or other materials provided
|
| 11 |
+
// with the distribution.
|
| 12 |
+
// * Neither the name of Google Inc. nor the names of its
|
| 13 |
+
// contributors may be used to endorse or promote products derived
|
| 14 |
+
// from this software without specific prior written permission.
|
| 15 |
+
//
|
| 16 |
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 17 |
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 18 |
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 19 |
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 20 |
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 21 |
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 22 |
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 23 |
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 24 |
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 25 |
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 26 |
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 |
+
|
| 28 |
+
#include <cmath>
|
| 29 |
+
|
| 30 |
+
#include "bignum-dtoa.h"
|
| 31 |
+
|
| 32 |
+
#include "bignum.h"
|
| 33 |
+
#include "ieee.h"
|
| 34 |
+
|
| 35 |
+
namespace double_conversion {
|
| 36 |
+
|
| 37 |
+
static int NormalizedExponent(uint64_t significand, int exponent) {
|
| 38 |
+
DOUBLE_CONVERSION_ASSERT(significand != 0);
|
| 39 |
+
while ((significand & Double::kHiddenBit) == 0) {
|
| 40 |
+
significand = significand << 1;
|
| 41 |
+
exponent = exponent - 1;
|
| 42 |
+
}
|
| 43 |
+
return exponent;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
// Forward declarations:
|
| 48 |
+
// Returns an estimation of k such that 10^(k-1) <= v < 10^k.
|
| 49 |
+
static int EstimatePower(int exponent);
|
| 50 |
+
// Computes v / 10^estimated_power exactly, as a ratio of two bignums, numerator
|
| 51 |
+
// and denominator.
|
| 52 |
+
static void InitialScaledStartValues(uint64_t significand,
|
| 53 |
+
int exponent,
|
| 54 |
+
bool lower_boundary_is_closer,
|
| 55 |
+
int estimated_power,
|
| 56 |
+
bool need_boundary_deltas,
|
| 57 |
+
Bignum* numerator,
|
| 58 |
+
Bignum* denominator,
|
| 59 |
+
Bignum* delta_minus,
|
| 60 |
+
Bignum* delta_plus);
|
| 61 |
+
// Multiplies numerator/denominator so that its values lies in the range 1-10.
|
| 62 |
+
// Returns decimal_point s.t.
|
| 63 |
+
// v = numerator'/denominator' * 10^(decimal_point-1)
|
| 64 |
+
// where numerator' and denominator' are the values of numerator and
|
| 65 |
+
// denominator after the call to this function.
|
| 66 |
+
static void FixupMultiply10(int estimated_power, bool is_even,
|
| 67 |
+
int* decimal_point,
|
| 68 |
+
Bignum* numerator, Bignum* denominator,
|
| 69 |
+
Bignum* delta_minus, Bignum* delta_plus);
|
| 70 |
+
// Generates digits from the left to the right and stops when the generated
|
| 71 |
+
// digits yield the shortest decimal representation of v.
|
| 72 |
+
static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
|
| 73 |
+
Bignum* delta_minus, Bignum* delta_plus,
|
| 74 |
+
bool is_even,
|
| 75 |
+
Vector<char> buffer, int* length);
|
| 76 |
+
// Generates 'requested_digits' after the decimal point.
|
| 77 |
+
static void BignumToFixed(int requested_digits, int* decimal_point,
|
| 78 |
+
Bignum* numerator, Bignum* denominator,
|
| 79 |
+
Vector<char> buffer, int* length);
|
| 80 |
+
// Generates 'count' digits of numerator/denominator.
|
| 81 |
+
// Once 'count' digits have been produced rounds the result depending on the
|
| 82 |
+
// remainder (remainders of exactly .5 round upwards). Might update the
|
| 83 |
+
// decimal_point when rounding up (for example for 0.9999).
|
| 84 |
+
static void GenerateCountedDigits(int count, int* decimal_point,
|
| 85 |
+
Bignum* numerator, Bignum* denominator,
|
| 86 |
+
Vector<char> buffer, int* length);
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
void BignumDtoa(double v, BignumDtoaMode mode, int requested_digits,
|
| 90 |
+
Vector<char> buffer, int* length, int* decimal_point) {
|
| 91 |
+
DOUBLE_CONVERSION_ASSERT(v > 0);
|
| 92 |
+
DOUBLE_CONVERSION_ASSERT(!Double(v).IsSpecial());
|
| 93 |
+
uint64_t significand;
|
| 94 |
+
int exponent;
|
| 95 |
+
bool lower_boundary_is_closer;
|
| 96 |
+
if (mode == BIGNUM_DTOA_SHORTEST_SINGLE) {
|
| 97 |
+
float f = static_cast<float>(v);
|
| 98 |
+
DOUBLE_CONVERSION_ASSERT(f == v);
|
| 99 |
+
significand = Single(f).Significand();
|
| 100 |
+
exponent = Single(f).Exponent();
|
| 101 |
+
lower_boundary_is_closer = Single(f).LowerBoundaryIsCloser();
|
| 102 |
+
} else {
|
| 103 |
+
significand = Double(v).Significand();
|
| 104 |
+
exponent = Double(v).Exponent();
|
| 105 |
+
lower_boundary_is_closer = Double(v).LowerBoundaryIsCloser();
|
| 106 |
+
}
|
| 107 |
+
bool need_boundary_deltas =
|
| 108 |
+
(mode == BIGNUM_DTOA_SHORTEST || mode == BIGNUM_DTOA_SHORTEST_SINGLE);
|
| 109 |
+
|
| 110 |
+
bool is_even = (significand & 1) == 0;
|
| 111 |
+
int normalized_exponent = NormalizedExponent(significand, exponent);
|
| 112 |
+
// estimated_power might be too low by 1.
|
| 113 |
+
int estimated_power = EstimatePower(normalized_exponent);
|
| 114 |
+
|
| 115 |
+
// Shortcut for Fixed.
|
| 116 |
+
// The requested digits correspond to the digits after the point. If the
|
| 117 |
+
// number is much too small, then there is no need in trying to get any
|
| 118 |
+
// digits.
|
| 119 |
+
if (mode == BIGNUM_DTOA_FIXED && -estimated_power - 1 > requested_digits) {
|
| 120 |
+
buffer[0] = '\0';
|
| 121 |
+
*length = 0;
|
| 122 |
+
// Set decimal-point to -requested_digits. This is what Gay does.
|
| 123 |
+
// Note that it should not have any effect anyways since the string is
|
| 124 |
+
// empty.
|
| 125 |
+
*decimal_point = -requested_digits;
|
| 126 |
+
return;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
Bignum numerator;
|
| 130 |
+
Bignum denominator;
|
| 131 |
+
Bignum delta_minus;
|
| 132 |
+
Bignum delta_plus;
|
| 133 |
+
// Make sure the bignum can grow large enough. The smallest double equals
|
| 134 |
+
// 4e-324. In this case the denominator needs fewer than 324*4 binary digits.
|
| 135 |
+
// The maximum double is 1.7976931348623157e308 which needs fewer than
|
| 136 |
+
// 308*4 binary digits.
|
| 137 |
+
DOUBLE_CONVERSION_ASSERT(Bignum::kMaxSignificantBits >= 324*4);
|
| 138 |
+
InitialScaledStartValues(significand, exponent, lower_boundary_is_closer,
|
| 139 |
+
estimated_power, need_boundary_deltas,
|
| 140 |
+
&numerator, &denominator,
|
| 141 |
+
&delta_minus, &delta_plus);
|
| 142 |
+
// We now have v = (numerator / denominator) * 10^estimated_power.
|
| 143 |
+
FixupMultiply10(estimated_power, is_even, decimal_point,
|
| 144 |
+
&numerator, &denominator,
|
| 145 |
+
&delta_minus, &delta_plus);
|
| 146 |
+
// We now have v = (numerator / denominator) * 10^(decimal_point-1), and
|
| 147 |
+
// 1 <= (numerator + delta_plus) / denominator < 10
|
| 148 |
+
switch (mode) {
|
| 149 |
+
case BIGNUM_DTOA_SHORTEST:
|
| 150 |
+
case BIGNUM_DTOA_SHORTEST_SINGLE:
|
| 151 |
+
GenerateShortestDigits(&numerator, &denominator,
|
| 152 |
+
&delta_minus, &delta_plus,
|
| 153 |
+
is_even, buffer, length);
|
| 154 |
+
break;
|
| 155 |
+
case BIGNUM_DTOA_FIXED:
|
| 156 |
+
BignumToFixed(requested_digits, decimal_point,
|
| 157 |
+
&numerator, &denominator,
|
| 158 |
+
buffer, length);
|
| 159 |
+
break;
|
| 160 |
+
case BIGNUM_DTOA_PRECISION:
|
| 161 |
+
GenerateCountedDigits(requested_digits, decimal_point,
|
| 162 |
+
&numerator, &denominator,
|
| 163 |
+
buffer, length);
|
| 164 |
+
break;
|
| 165 |
+
default:
|
| 166 |
+
DOUBLE_CONVERSION_UNREACHABLE();
|
| 167 |
+
}
|
| 168 |
+
buffer[*length] = '\0';
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
// The procedure starts generating digits from the left to the right and stops
|
| 173 |
+
// when the generated digits yield the shortest decimal representation of v. A
|
| 174 |
+
// decimal representation of v is a number lying closer to v than to any other
|
| 175 |
+
// double, so it converts to v when read.
|
| 176 |
+
//
|
| 177 |
+
// This is true if d, the decimal representation, is between m- and m+, the
|
| 178 |
+
// upper and lower boundaries. d must be strictly between them if !is_even.
|
| 179 |
+
// m- := (numerator - delta_minus) / denominator
|
| 180 |
+
// m+ := (numerator + delta_plus) / denominator
|
| 181 |
+
//
|
| 182 |
+
// Precondition: 0 <= (numerator+delta_plus) / denominator < 10.
|
| 183 |
+
// If 1 <= (numerator+delta_plus) / denominator < 10 then no leading 0 digit
|
| 184 |
+
// will be produced. This should be the standard precondition.
|
| 185 |
+
static void GenerateShortestDigits(Bignum* numerator, Bignum* denominator,
|
| 186 |
+
Bignum* delta_minus, Bignum* delta_plus,
|
| 187 |
+
bool is_even,
|
| 188 |
+
Vector<char> buffer, int* length) {
|
| 189 |
+
// Small optimization: if delta_minus and delta_plus are the same just reuse
|
| 190 |
+
// one of the two bignums.
|
| 191 |
+
if (Bignum::Equal(*delta_minus, *delta_plus)) {
|
| 192 |
+
delta_plus = delta_minus;
|
| 193 |
+
}
|
| 194 |
+
*length = 0;
|
| 195 |
+
for (;;) {
|
| 196 |
+
uint16_t digit;
|
| 197 |
+
digit = numerator->DivideModuloIntBignum(*denominator);
|
| 198 |
+
DOUBLE_CONVERSION_ASSERT(digit <= 9); // digit is a uint16_t and therefore always positive.
|
| 199 |
+
// digit = numerator / denominator (integer division).
|
| 200 |
+
// numerator = numerator % denominator.
|
| 201 |
+
buffer[(*length)++] = static_cast<char>(digit + '0');
|
| 202 |
+
|
| 203 |
+
// Can we stop already?
|
| 204 |
+
// If the remainder of the division is less than the distance to the lower
|
| 205 |
+
// boundary we can stop. In this case we simply round down (discarding the
|
| 206 |
+
// remainder).
|
| 207 |
+
// Similarly we test if we can round up (using the upper boundary).
|
| 208 |
+
bool in_delta_room_minus;
|
| 209 |
+
bool in_delta_room_plus;
|
| 210 |
+
if (is_even) {
|
| 211 |
+
in_delta_room_minus = Bignum::LessEqual(*numerator, *delta_minus);
|
| 212 |
+
} else {
|
| 213 |
+
in_delta_room_minus = Bignum::Less(*numerator, *delta_minus);
|
| 214 |
+
}
|
| 215 |
+
if (is_even) {
|
| 216 |
+
in_delta_room_plus =
|
| 217 |
+
Bignum::PlusCompare(*numerator, *delta_plus, *denominator) >= 0;
|
| 218 |
+
} else {
|
| 219 |
+
in_delta_room_plus =
|
| 220 |
+
Bignum::PlusCompare(*numerator, *delta_plus, *denominator) > 0;
|
| 221 |
+
}
|
| 222 |
+
if (!in_delta_room_minus && !in_delta_room_plus) {
|
| 223 |
+
// Prepare for next iteration.
|
| 224 |
+
numerator->Times10();
|
| 225 |
+
delta_minus->Times10();
|
| 226 |
+
// We optimized delta_plus to be equal to delta_minus (if they share the
|
| 227 |
+
// same value). So don't multiply delta_plus if they point to the same
|
| 228 |
+
// object.
|
| 229 |
+
if (delta_minus != delta_plus) {
|
| 230 |
+
delta_plus->Times10();
|
| 231 |
+
}
|
| 232 |
+
} else if (in_delta_room_minus && in_delta_room_plus) {
|
| 233 |
+
// Let's see if 2*numerator < denominator.
|
| 234 |
+
// If yes, then the next digit would be < 5 and we can round down.
|
| 235 |
+
int compare = Bignum::PlusCompare(*numerator, *numerator, *denominator);
|
| 236 |
+
if (compare < 0) {
|
| 237 |
+
// Remaining digits are less than .5. -> Round down (== do nothing).
|
| 238 |
+
} else if (compare > 0) {
|
| 239 |
+
// Remaining digits are more than .5 of denominator. -> Round up.
|
| 240 |
+
// Note that the last digit could not be a '9' as otherwise the whole
|
| 241 |
+
// loop would have stopped earlier.
|
| 242 |
+
// We still have an assert here in case the preconditions were not
|
| 243 |
+
// satisfied.
|
| 244 |
+
DOUBLE_CONVERSION_ASSERT(buffer[(*length) - 1] != '9');
|
| 245 |
+
buffer[(*length) - 1]++;
|
| 246 |
+
} else {
|
| 247 |
+
// Halfway case.
|
| 248 |
+
// TODO(floitsch): need a way to solve half-way cases.
|
| 249 |
+
// For now let's round towards even (since this is what Gay seems to
|
| 250 |
+
// do).
|
| 251 |
+
|
| 252 |
+
if ((buffer[(*length) - 1] - '0') % 2 == 0) {
|
| 253 |
+
// Round down => Do nothing.
|
| 254 |
+
} else {
|
| 255 |
+
DOUBLE_CONVERSION_ASSERT(buffer[(*length) - 1] != '9');
|
| 256 |
+
buffer[(*length) - 1]++;
|
| 257 |
+
}
|
| 258 |
+
}
|
| 259 |
+
return;
|
| 260 |
+
} else if (in_delta_room_minus) {
|
| 261 |
+
// Round down (== do nothing).
|
| 262 |
+
return;
|
| 263 |
+
} else { // in_delta_room_plus
|
| 264 |
+
// Round up.
|
| 265 |
+
// Note again that the last digit could not be '9' since this would have
|
| 266 |
+
// stopped the loop earlier.
|
| 267 |
+
// We still have an DOUBLE_CONVERSION_ASSERT here, in case the preconditions were not
|
| 268 |
+
// satisfied.
|
| 269 |
+
DOUBLE_CONVERSION_ASSERT(buffer[(*length) -1] != '9');
|
| 270 |
+
buffer[(*length) - 1]++;
|
| 271 |
+
return;
|
| 272 |
+
}
|
| 273 |
+
}
|
| 274 |
+
}
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
// Let v = numerator / denominator < 10.
|
| 278 |
+
// Then we generate 'count' digits of d = x.xxxxx... (without the decimal point)
|
| 279 |
+
// from left to right. Once 'count' digits have been produced we decide whether
|
| 280 |
+
// to round up or down. Remainders of exactly .5 round upwards. Numbers such
|
| 281 |
+
// as 9.999999 propagate a carry all the way, and change the
|
| 282 |
+
// exponent (decimal_point), when rounding upwards.
|
| 283 |
+
static void GenerateCountedDigits(int count, int* decimal_point,
|
| 284 |
+
Bignum* numerator, Bignum* denominator,
|
| 285 |
+
Vector<char> buffer, int* length) {
|
| 286 |
+
DOUBLE_CONVERSION_ASSERT(count >= 0);
|
| 287 |
+
for (int i = 0; i < count - 1; ++i) {
|
| 288 |
+
uint16_t digit;
|
| 289 |
+
digit = numerator->DivideModuloIntBignum(*denominator);
|
| 290 |
+
DOUBLE_CONVERSION_ASSERT(digit <= 9); // digit is a uint16_t and therefore always positive.
|
| 291 |
+
// digit = numerator / denominator (integer division).
|
| 292 |
+
// numerator = numerator % denominator.
|
| 293 |
+
buffer[i] = static_cast<char>(digit + '0');
|
| 294 |
+
// Prepare for next iteration.
|
| 295 |
+
numerator->Times10();
|
| 296 |
+
}
|
| 297 |
+
// Generate the last digit.
|
| 298 |
+
uint16_t digit;
|
| 299 |
+
digit = numerator->DivideModuloIntBignum(*denominator);
|
| 300 |
+
if (Bignum::PlusCompare(*numerator, *numerator, *denominator) >= 0) {
|
| 301 |
+
digit++;
|
| 302 |
+
}
|
| 303 |
+
DOUBLE_CONVERSION_ASSERT(digit <= 10);
|
| 304 |
+
buffer[count - 1] = static_cast<char>(digit + '0');
|
| 305 |
+
// Correct bad digits (in case we had a sequence of '9's). Propagate the
|
| 306 |
+
// carry until we hat a non-'9' or til we reach the first digit.
|
| 307 |
+
for (int i = count - 1; i > 0; --i) {
|
| 308 |
+
if (buffer[i] != '0' + 10) break;
|
| 309 |
+
buffer[i] = '0';
|
| 310 |
+
buffer[i - 1]++;
|
| 311 |
+
}
|
| 312 |
+
if (buffer[0] == '0' + 10) {
|
| 313 |
+
// Propagate a carry past the top place.
|
| 314 |
+
buffer[0] = '1';
|
| 315 |
+
(*decimal_point)++;
|
| 316 |
+
}
|
| 317 |
+
*length = count;
|
| 318 |
+
}
|
| 319 |
+
|
| 320 |
+
|
| 321 |
+
// Generates 'requested_digits' after the decimal point. It might omit
|
| 322 |
+
// trailing '0's. If the input number is too small then no digits at all are
|
| 323 |
+
// generated (ex.: 2 fixed digits for 0.00001).
|
| 324 |
+
//
|
| 325 |
+
// Input verifies: 1 <= (numerator + delta) / denominator < 10.
|
| 326 |
+
static void BignumToFixed(int requested_digits, int* decimal_point,
|
| 327 |
+
Bignum* numerator, Bignum* denominator,
|
| 328 |
+
Vector<char> buffer, int* length) {
|
| 329 |
+
// Note that we have to look at more than just the requested_digits, since
|
| 330 |
+
// a number could be rounded up. Example: v=0.5 with requested_digits=0.
|
| 331 |
+
// Even though the power of v equals 0 we can't just stop here.
|
| 332 |
+
if (-(*decimal_point) > requested_digits) {
|
| 333 |
+
// The number is definitively too small.
|
| 334 |
+
// Ex: 0.001 with requested_digits == 1.
|
| 335 |
+
// Set decimal-point to -requested_digits. This is what Gay does.
|
| 336 |
+
// Note that it should not have any effect anyways since the string is
|
| 337 |
+
// empty.
|
| 338 |
+
*decimal_point = -requested_digits;
|
| 339 |
+
*length = 0;
|
| 340 |
+
return;
|
| 341 |
+
} else if (-(*decimal_point) == requested_digits) {
|
| 342 |
+
// We only need to verify if the number rounds down or up.
|
| 343 |
+
// Ex: 0.04 and 0.06 with requested_digits == 1.
|
| 344 |
+
DOUBLE_CONVERSION_ASSERT(*decimal_point == -requested_digits);
|
| 345 |
+
// Initially the fraction lies in range (1, 10]. Multiply the denominator
|
| 346 |
+
// by 10 so that we can compare more easily.
|
| 347 |
+
denominator->Times10();
|
| 348 |
+
if (Bignum::PlusCompare(*numerator, *numerator, *denominator) >= 0) {
|
| 349 |
+
// If the fraction is >= 0.5 then we have to include the rounded
|
| 350 |
+
// digit.
|
| 351 |
+
buffer[0] = '1';
|
| 352 |
+
*length = 1;
|
| 353 |
+
(*decimal_point)++;
|
| 354 |
+
} else {
|
| 355 |
+
// Note that we caught most of similar cases earlier.
|
| 356 |
+
*length = 0;
|
| 357 |
+
}
|
| 358 |
+
return;
|
| 359 |
+
} else {
|
| 360 |
+
// The requested digits correspond to the digits after the point.
|
| 361 |
+
// The variable 'needed_digits' includes the digits before the point.
|
| 362 |
+
int needed_digits = (*decimal_point) + requested_digits;
|
| 363 |
+
GenerateCountedDigits(needed_digits, decimal_point,
|
| 364 |
+
numerator, denominator,
|
| 365 |
+
buffer, length);
|
| 366 |
+
}
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
// Returns an estimation of k such that 10^(k-1) <= v < 10^k where
|
| 371 |
+
// v = f * 2^exponent and 2^52 <= f < 2^53.
|
| 372 |
+
// v is hence a normalized double with the given exponent. The output is an
|
| 373 |
+
// approximation for the exponent of the decimal approximation .digits * 10^k.
|
| 374 |
+
//
|
| 375 |
+
// The result might undershoot by 1 in which case 10^k <= v < 10^k+1.
|
| 376 |
+
// Note: this property holds for v's upper boundary m+ too.
|
| 377 |
+
// 10^k <= m+ < 10^k+1.
|
| 378 |
+
// (see explanation below).
|
| 379 |
+
//
|
| 380 |
+
// Examples:
|
| 381 |
+
// EstimatePower(0) => 16
|
| 382 |
+
// EstimatePower(-52) => 0
|
| 383 |
+
//
|
| 384 |
+
// Note: e >= 0 => EstimatedPower(e) > 0. No similar claim can be made for e<0.
|
| 385 |
+
static int EstimatePower(int exponent) {
|
| 386 |
+
// This function estimates log10 of v where v = f*2^e (with e == exponent).
|
| 387 |
+
// Note that 10^floor(log10(v)) <= v, but v <= 10^ceil(log10(v)).
|
| 388 |
+
// Note that f is bounded by its container size. Let p = 53 (the double's
|
| 389 |
+
// significand size). Then 2^(p-1) <= f < 2^p.
|
| 390 |
+
//
|
| 391 |
+
// Given that log10(v) == log2(v)/log2(10) and e+(len(f)-1) is quite close
|
| 392 |
+
// to log2(v) the function is simplified to (e+(len(f)-1)/log2(10)).
|
| 393 |
+
// The computed number undershoots by less than 0.631 (when we compute log3
|
| 394 |
+
// and not log10).
|
| 395 |
+
//
|
| 396 |
+
// Optimization: since we only need an approximated result this computation
|
| 397 |
+
// can be performed on 64 bit integers. On x86/x64 architecture the speedup is
|
| 398 |
+
// not really measurable, though.
|
| 399 |
+
//
|
| 400 |
+
// Since we want to avoid overshooting we decrement by 1e10 so that
|
| 401 |
+
// floating-point imprecisions don't affect us.
|
| 402 |
+
//
|
| 403 |
+
// Explanation for v's boundary m+: the computation takes advantage of
|
| 404 |
+
// the fact that 2^(p-1) <= f < 2^p. Boundaries still satisfy this requirement
|
| 405 |
+
// (even for denormals where the delta can be much more important).
|
| 406 |
+
|
| 407 |
+
const double k1Log10 = 0.30102999566398114; // 1/lg(10)
|
| 408 |
+
|
| 409 |
+
// For doubles len(f) == 53 (don't forget the hidden bit).
|
| 410 |
+
const int kSignificandSize = Double::kSignificandSize;
|
| 411 |
+
double estimate = ceil((exponent + kSignificandSize - 1) * k1Log10 - 1e-10);
|
| 412 |
+
return static_cast<int>(estimate);
|
| 413 |
+
}
|
| 414 |
+
|
| 415 |
+
|
| 416 |
+
// See comments for InitialScaledStartValues.
|
| 417 |
+
static void InitialScaledStartValuesPositiveExponent(
|
| 418 |
+
uint64_t significand, int exponent,
|
| 419 |
+
int estimated_power, bool need_boundary_deltas,
|
| 420 |
+
Bignum* numerator, Bignum* denominator,
|
| 421 |
+
Bignum* delta_minus, Bignum* delta_plus) {
|
| 422 |
+
// A positive exponent implies a positive power.
|
| 423 |
+
DOUBLE_CONVERSION_ASSERT(estimated_power >= 0);
|
| 424 |
+
// Since the estimated_power is positive we simply multiply the denominator
|
| 425 |
+
// by 10^estimated_power.
|
| 426 |
+
|
| 427 |
+
// numerator = v.
|
| 428 |
+
numerator->AssignUInt64(significand);
|
| 429 |
+
numerator->ShiftLeft(exponent);
|
| 430 |
+
// denominator = 10^estimated_power.
|
| 431 |
+
denominator->AssignPowerUInt16(10, estimated_power);
|
| 432 |
+
|
| 433 |
+
if (need_boundary_deltas) {
|
| 434 |
+
// Introduce a common denominator so that the deltas to the boundaries are
|
| 435 |
+
// integers.
|
| 436 |
+
denominator->ShiftLeft(1);
|
| 437 |
+
numerator->ShiftLeft(1);
|
| 438 |
+
// Let v = f * 2^e, then m+ - v = 1/2 * 2^e; With the common
|
| 439 |
+
// denominator (of 2) delta_plus equals 2^e.
|
| 440 |
+
delta_plus->AssignUInt16(1);
|
| 441 |
+
delta_plus->ShiftLeft(exponent);
|
| 442 |
+
// Same for delta_minus. The adjustments if f == 2^p-1 are done later.
|
| 443 |
+
delta_minus->AssignUInt16(1);
|
| 444 |
+
delta_minus->ShiftLeft(exponent);
|
| 445 |
+
}
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
// See comments for InitialScaledStartValues
|
| 450 |
+
static void InitialScaledStartValuesNegativeExponentPositivePower(
|
| 451 |
+
uint64_t significand, int exponent,
|
| 452 |
+
int estimated_power, bool need_boundary_deltas,
|
| 453 |
+
Bignum* numerator, Bignum* denominator,
|
| 454 |
+
Bignum* delta_minus, Bignum* delta_plus) {
|
| 455 |
+
// v = f * 2^e with e < 0, and with estimated_power >= 0.
|
| 456 |
+
// This means that e is close to 0 (have a look at how estimated_power is
|
| 457 |
+
// computed).
|
| 458 |
+
|
| 459 |
+
// numerator = significand
|
| 460 |
+
// since v = significand * 2^exponent this is equivalent to
|
| 461 |
+
// numerator = v * / 2^-exponent
|
| 462 |
+
numerator->AssignUInt64(significand);
|
| 463 |
+
// denominator = 10^estimated_power * 2^-exponent (with exponent < 0)
|
| 464 |
+
denominator->AssignPowerUInt16(10, estimated_power);
|
| 465 |
+
denominator->ShiftLeft(-exponent);
|
| 466 |
+
|
| 467 |
+
if (need_boundary_deltas) {
|
| 468 |
+
// Introduce a common denominator so that the deltas to the boundaries are
|
| 469 |
+
// integers.
|
| 470 |
+
denominator->ShiftLeft(1);
|
| 471 |
+
numerator->ShiftLeft(1);
|
| 472 |
+
// Let v = f * 2^e, then m+ - v = 1/2 * 2^e; With the common
|
| 473 |
+
// denominator (of 2) delta_plus equals 2^e.
|
| 474 |
+
// Given that the denominator already includes v's exponent the distance
|
| 475 |
+
// to the boundaries is simply 1.
|
| 476 |
+
delta_plus->AssignUInt16(1);
|
| 477 |
+
// Same for delta_minus. The adjustments if f == 2^p-1 are done later.
|
| 478 |
+
delta_minus->AssignUInt16(1);
|
| 479 |
+
}
|
| 480 |
+
}
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
// See comments for InitialScaledStartValues
|
| 484 |
+
static void InitialScaledStartValuesNegativeExponentNegativePower(
|
| 485 |
+
uint64_t significand, int exponent,
|
| 486 |
+
int estimated_power, bool need_boundary_deltas,
|
| 487 |
+
Bignum* numerator, Bignum* denominator,
|
| 488 |
+
Bignum* delta_minus, Bignum* delta_plus) {
|
| 489 |
+
// Instead of multiplying the denominator with 10^estimated_power we
|
| 490 |
+
// multiply all values (numerator and deltas) by 10^-estimated_power.
|
| 491 |
+
|
| 492 |
+
// Use numerator as temporary container for power_ten.
|
| 493 |
+
Bignum* power_ten = numerator;
|
| 494 |
+
power_ten->AssignPowerUInt16(10, -estimated_power);
|
| 495 |
+
|
| 496 |
+
if (need_boundary_deltas) {
|
| 497 |
+
// Since power_ten == numerator we must make a copy of 10^estimated_power
|
| 498 |
+
// before we complete the computation of the numerator.
|
| 499 |
+
// delta_plus = delta_minus = 10^estimated_power
|
| 500 |
+
delta_plus->AssignBignum(*power_ten);
|
| 501 |
+
delta_minus->AssignBignum(*power_ten);
|
| 502 |
+
}
|
| 503 |
+
|
| 504 |
+
// numerator = significand * 2 * 10^-estimated_power
|
| 505 |
+
// since v = significand * 2^exponent this is equivalent to
|
| 506 |
+
// numerator = v * 10^-estimated_power * 2 * 2^-exponent.
|
| 507 |
+
// Remember: numerator has been abused as power_ten. So no need to assign it
|
| 508 |
+
// to itself.
|
| 509 |
+
DOUBLE_CONVERSION_ASSERT(numerator == power_ten);
|
| 510 |
+
numerator->MultiplyByUInt64(significand);
|
| 511 |
+
|
| 512 |
+
// denominator = 2 * 2^-exponent with exponent < 0.
|
| 513 |
+
denominator->AssignUInt16(1);
|
| 514 |
+
denominator->ShiftLeft(-exponent);
|
| 515 |
+
|
| 516 |
+
if (need_boundary_deltas) {
|
| 517 |
+
// Introduce a common denominator so that the deltas to the boundaries are
|
| 518 |
+
// integers.
|
| 519 |
+
numerator->ShiftLeft(1);
|
| 520 |
+
denominator->ShiftLeft(1);
|
| 521 |
+
// With this shift the boundaries have their correct value, since
|
| 522 |
+
// delta_plus = 10^-estimated_power, and
|
| 523 |
+
// delta_minus = 10^-estimated_power.
|
| 524 |
+
// These assignments have been done earlier.
|
| 525 |
+
// The adjustments if f == 2^p-1 (lower boundary is closer) are done later.
|
| 526 |
+
}
|
| 527 |
+
}
|
| 528 |
+
|
| 529 |
+
|
| 530 |
+
// Let v = significand * 2^exponent.
|
| 531 |
+
// Computes v / 10^estimated_power exactly, as a ratio of two bignums, numerator
|
| 532 |
+
// and denominator. The functions GenerateShortestDigits and
|
| 533 |
+
// GenerateCountedDigits will then convert this ratio to its decimal
|
| 534 |
+
// representation d, with the required accuracy.
|
| 535 |
+
// Then d * 10^estimated_power is the representation of v.
|
| 536 |
+
// (Note: the fraction and the estimated_power might get adjusted before
|
| 537 |
+
// generating the decimal representation.)
|
| 538 |
+
//
|
| 539 |
+
// The initial start values consist of:
|
| 540 |
+
// - a scaled numerator: s.t. numerator/denominator == v / 10^estimated_power.
|
| 541 |
+
// - a scaled (common) denominator.
|
| 542 |
+
// optionally (used by GenerateShortestDigits to decide if it has the shortest
|
| 543 |
+
// decimal converting back to v):
|
| 544 |
+
// - v - m-: the distance to the lower boundary.
|
| 545 |
+
// - m+ - v: the distance to the upper boundary.
|
| 546 |
+
//
|
| 547 |
+
// v, m+, m-, and therefore v - m- and m+ - v all share the same denominator.
|
| 548 |
+
//
|
| 549 |
+
// Let ep == estimated_power, then the returned values will satisfy:
|
| 550 |
+
// v / 10^ep = numerator / denominator.
|
| 551 |
+
// v's boundaries m- and m+:
|
| 552 |
+
// m- / 10^ep == v / 10^ep - delta_minus / denominator
|
| 553 |
+
// m+ / 10^ep == v / 10^ep + delta_plus / denominator
|
| 554 |
+
// Or in other words:
|
| 555 |
+
// m- == v - delta_minus * 10^ep / denominator;
|
| 556 |
+
// m+ == v + delta_plus * 10^ep / denominator;
|
| 557 |
+
//
|
| 558 |
+
// Since 10^(k-1) <= v < 10^k (with k == estimated_power)
|
| 559 |
+
// or 10^k <= v < 10^(k+1)
|
| 560 |
+
// we then have 0.1 <= numerator/denominator < 1
|
| 561 |
+
// or 1 <= numerator/denominator < 10
|
| 562 |
+
//
|
| 563 |
+
// It is then easy to kickstart the digit-generation routine.
|
| 564 |
+
//
|
| 565 |
+
// The boundary-deltas are only filled if the mode equals BIGNUM_DTOA_SHORTEST
|
| 566 |
+
// or BIGNUM_DTOA_SHORTEST_SINGLE.
|
| 567 |
+
|
| 568 |
+
static void InitialScaledStartValues(uint64_t significand,
|
| 569 |
+
int exponent,
|
| 570 |
+
bool lower_boundary_is_closer,
|
| 571 |
+
int estimated_power,
|
| 572 |
+
bool need_boundary_deltas,
|
| 573 |
+
Bignum* numerator,
|
| 574 |
+
Bignum* denominator,
|
| 575 |
+
Bignum* delta_minus,
|
| 576 |
+
Bignum* delta_plus) {
|
| 577 |
+
if (exponent >= 0) {
|
| 578 |
+
InitialScaledStartValuesPositiveExponent(
|
| 579 |
+
significand, exponent, estimated_power, need_boundary_deltas,
|
| 580 |
+
numerator, denominator, delta_minus, delta_plus);
|
| 581 |
+
} else if (estimated_power >= 0) {
|
| 582 |
+
InitialScaledStartValuesNegativeExponentPositivePower(
|
| 583 |
+
significand, exponent, estimated_power, need_boundary_deltas,
|
| 584 |
+
numerator, denominator, delta_minus, delta_plus);
|
| 585 |
+
} else {
|
| 586 |
+
InitialScaledStartValuesNegativeExponentNegativePower(
|
| 587 |
+
significand, exponent, estimated_power, need_boundary_deltas,
|
| 588 |
+
numerator, denominator, delta_minus, delta_plus);
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
if (need_boundary_deltas && lower_boundary_is_closer) {
|
| 592 |
+
// The lower boundary is closer at half the distance of "normal" numbers.
|
| 593 |
+
// Increase the common denominator and adapt all but the delta_minus.
|
| 594 |
+
denominator->ShiftLeft(1); // *2
|
| 595 |
+
numerator->ShiftLeft(1); // *2
|
| 596 |
+
delta_plus->ShiftLeft(1); // *2
|
| 597 |
+
}
|
| 598 |
+
}
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
// This routine multiplies numerator/denominator so that its values lies in the
|
| 602 |
+
// range 1-10. That is after a call to this function we have:
|
| 603 |
+
// 1 <= (numerator + delta_plus) /denominator < 10.
|
| 604 |
+
// Let numerator the input before modification and numerator' the argument
|
| 605 |
+
// after modification, then the output-parameter decimal_point is such that
|
| 606 |
+
// numerator / denominator * 10^estimated_power ==
|
| 607 |
+
// numerator' / denominator' * 10^(decimal_point - 1)
|
| 608 |
+
// In some cases estimated_power was too low, and this is already the case. We
|
| 609 |
+
// then simply adjust the power so that 10^(k-1) <= v < 10^k (with k ==
|
| 610 |
+
// estimated_power) but do not touch the numerator or denominator.
|
| 611 |
+
// Otherwise the routine multiplies the numerator and the deltas by 10.
|
| 612 |
+
static void FixupMultiply10(int estimated_power, bool is_even,
|
| 613 |
+
int* decimal_point,
|
| 614 |
+
Bignum* numerator, Bignum* denominator,
|
| 615 |
+
Bignum* delta_minus, Bignum* delta_plus) {
|
| 616 |
+
bool in_range;
|
| 617 |
+
if (is_even) {
|
| 618 |
+
// For IEEE doubles half-way cases (in decimal system numbers ending with 5)
|
| 619 |
+
// are rounded to the closest floating-point number with even significand.
|
| 620 |
+
in_range = Bignum::PlusCompare(*numerator, *delta_plus, *denominator) >= 0;
|
| 621 |
+
} else {
|
| 622 |
+
in_range = Bignum::PlusCompare(*numerator, *delta_plus, *denominator) > 0;
|
| 623 |
+
}
|
| 624 |
+
if (in_range) {
|
| 625 |
+
// Since numerator + delta_plus >= denominator we already have
|
| 626 |
+
// 1 <= numerator/denominator < 10. Simply update the estimated_power.
|
| 627 |
+
*decimal_point = estimated_power + 1;
|
| 628 |
+
} else {
|
| 629 |
+
*decimal_point = estimated_power;
|
| 630 |
+
numerator->Times10();
|
| 631 |
+
if (Bignum::Equal(*delta_minus, *delta_plus)) {
|
| 632 |
+
delta_minus->Times10();
|
| 633 |
+
delta_plus->AssignBignum(*delta_minus);
|
| 634 |
+
} else {
|
| 635 |
+
delta_minus->Times10();
|
| 636 |
+
delta_plus->Times10();
|
| 637 |
+
}
|
| 638 |
+
}
|
| 639 |
+
}
|
| 640 |
+
|
| 641 |
+
} // namespace double_conversion
|
cpp-compiled/sources/double-conversion/bignum-dtoa.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/bignum.cc
ADDED
|
@@ -0,0 +1,797 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2010 the V8 project authors. All rights reserved.
|
| 2 |
+
// Redistribution and use in source and binary forms, with or without
|
| 3 |
+
// modification, are permitted provided that the following conditions are
|
| 4 |
+
// met:
|
| 5 |
+
//
|
| 6 |
+
// * Redistributions of source code must retain the above copyright
|
| 7 |
+
// notice, this list of conditions and the following disclaimer.
|
| 8 |
+
// * Redistributions in binary form must reproduce the above
|
| 9 |
+
// copyright notice, this list of conditions and the following
|
| 10 |
+
// disclaimer in the documentation and/or other materials provided
|
| 11 |
+
// with the distribution.
|
| 12 |
+
// * Neither the name of Google Inc. nor the names of its
|
| 13 |
+
// contributors may be used to endorse or promote products derived
|
| 14 |
+
// from this software without specific prior written permission.
|
| 15 |
+
//
|
| 16 |
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 17 |
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 18 |
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 19 |
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 20 |
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 21 |
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 22 |
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 23 |
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 24 |
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 25 |
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 26 |
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 |
+
|
| 28 |
+
#include <algorithm>
|
| 29 |
+
#include <cstring>
|
| 30 |
+
|
| 31 |
+
#include "bignum.h"
|
| 32 |
+
#include "utils.h"
|
| 33 |
+
|
| 34 |
+
namespace double_conversion {
|
| 35 |
+
|
| 36 |
+
Bignum::Chunk& Bignum::RawBigit(const int index) {
|
| 37 |
+
DOUBLE_CONVERSION_ASSERT(static_cast<unsigned>(index) < kBigitCapacity);
|
| 38 |
+
return bigits_buffer_[index];
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
const Bignum::Chunk& Bignum::RawBigit(const int index) const {
|
| 43 |
+
DOUBLE_CONVERSION_ASSERT(static_cast<unsigned>(index) < kBigitCapacity);
|
| 44 |
+
return bigits_buffer_[index];
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
template<typename S>
|
| 49 |
+
static int BitSize(const S value) {
|
| 50 |
+
(void) value; // Mark variable as used.
|
| 51 |
+
return 8 * sizeof(value);
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
// Guaranteed to lie in one Bigit.
|
| 55 |
+
void Bignum::AssignUInt16(const uint16_t value) {
|
| 56 |
+
DOUBLE_CONVERSION_ASSERT(kBigitSize >= BitSize(value));
|
| 57 |
+
Zero();
|
| 58 |
+
if (value > 0) {
|
| 59 |
+
RawBigit(0) = value;
|
| 60 |
+
used_bigits_ = 1;
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
void Bignum::AssignUInt64(uint64_t value) {
|
| 66 |
+
Zero();
|
| 67 |
+
for(int i = 0; value > 0; ++i) {
|
| 68 |
+
RawBigit(i) = value & kBigitMask;
|
| 69 |
+
value >>= kBigitSize;
|
| 70 |
+
++used_bigits_;
|
| 71 |
+
}
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
void Bignum::AssignBignum(const Bignum& other) {
|
| 76 |
+
exponent_ = other.exponent_;
|
| 77 |
+
for (int i = 0; i < other.used_bigits_; ++i) {
|
| 78 |
+
RawBigit(i) = other.RawBigit(i);
|
| 79 |
+
}
|
| 80 |
+
used_bigits_ = other.used_bigits_;
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
static uint64_t ReadUInt64(const Vector<const char> buffer,
|
| 85 |
+
const int from,
|
| 86 |
+
const int digits_to_read) {
|
| 87 |
+
uint64_t result = 0;
|
| 88 |
+
for (int i = from; i < from + digits_to_read; ++i) {
|
| 89 |
+
const int digit = buffer[i] - '0';
|
| 90 |
+
DOUBLE_CONVERSION_ASSERT(0 <= digit && digit <= 9);
|
| 91 |
+
result = result * 10 + digit;
|
| 92 |
+
}
|
| 93 |
+
return result;
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
void Bignum::AssignDecimalString(const Vector<const char> value) {
|
| 98 |
+
// 2^64 = 18446744073709551616 > 10^19
|
| 99 |
+
static const int kMaxUint64DecimalDigits = 19;
|
| 100 |
+
Zero();
|
| 101 |
+
int length = value.length();
|
| 102 |
+
unsigned pos = 0;
|
| 103 |
+
// Let's just say that each digit needs 4 bits.
|
| 104 |
+
while (length >= kMaxUint64DecimalDigits) {
|
| 105 |
+
const uint64_t digits = ReadUInt64(value, pos, kMaxUint64DecimalDigits);
|
| 106 |
+
pos += kMaxUint64DecimalDigits;
|
| 107 |
+
length -= kMaxUint64DecimalDigits;
|
| 108 |
+
MultiplyByPowerOfTen(kMaxUint64DecimalDigits);
|
| 109 |
+
AddUInt64(digits);
|
| 110 |
+
}
|
| 111 |
+
const uint64_t digits = ReadUInt64(value, pos, length);
|
| 112 |
+
MultiplyByPowerOfTen(length);
|
| 113 |
+
AddUInt64(digits);
|
| 114 |
+
Clamp();
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
static uint64_t HexCharValue(const int c) {
|
| 119 |
+
if ('0' <= c && c <= '9') {
|
| 120 |
+
return c - '0';
|
| 121 |
+
}
|
| 122 |
+
if ('a' <= c && c <= 'f') {
|
| 123 |
+
return 10 + c - 'a';
|
| 124 |
+
}
|
| 125 |
+
DOUBLE_CONVERSION_ASSERT('A' <= c && c <= 'F');
|
| 126 |
+
return 10 + c - 'A';
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
// Unlike AssignDecimalString(), this function is "only" used
|
| 131 |
+
// for unit-tests and therefore not performance critical.
|
| 132 |
+
void Bignum::AssignHexString(Vector<const char> value) {
|
| 133 |
+
Zero();
|
| 134 |
+
// Required capacity could be reduced by ignoring leading zeros.
|
| 135 |
+
EnsureCapacity(((value.length() * 4) + kBigitSize - 1) / kBigitSize);
|
| 136 |
+
DOUBLE_CONVERSION_ASSERT(sizeof(uint64_t) * 8 >= kBigitSize + 4); // TODO: static_assert
|
| 137 |
+
// Accumulates converted hex digits until at least kBigitSize bits.
|
| 138 |
+
// Works with non-factor-of-four kBigitSizes.
|
| 139 |
+
uint64_t tmp = 0;
|
| 140 |
+
for (int cnt = 0; !value.is_empty(); value.pop_back()) {
|
| 141 |
+
tmp |= (HexCharValue(value.last()) << cnt);
|
| 142 |
+
if ((cnt += 4) >= kBigitSize) {
|
| 143 |
+
RawBigit(used_bigits_++) = (tmp & kBigitMask);
|
| 144 |
+
cnt -= kBigitSize;
|
| 145 |
+
tmp >>= kBigitSize;
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
if (tmp > 0) {
|
| 149 |
+
DOUBLE_CONVERSION_ASSERT(tmp <= kBigitMask);
|
| 150 |
+
RawBigit(used_bigits_++) = static_cast<Bignum::Chunk>(tmp & kBigitMask);
|
| 151 |
+
}
|
| 152 |
+
Clamp();
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
void Bignum::AddUInt64(const uint64_t operand) {
|
| 157 |
+
if (operand == 0) {
|
| 158 |
+
return;
|
| 159 |
+
}
|
| 160 |
+
Bignum other;
|
| 161 |
+
other.AssignUInt64(operand);
|
| 162 |
+
AddBignum(other);
|
| 163 |
+
}
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
void Bignum::AddBignum(const Bignum& other) {
|
| 167 |
+
DOUBLE_CONVERSION_ASSERT(IsClamped());
|
| 168 |
+
DOUBLE_CONVERSION_ASSERT(other.IsClamped());
|
| 169 |
+
|
| 170 |
+
// If this has a greater exponent than other append zero-bigits to this.
|
| 171 |
+
// After this call exponent_ <= other.exponent_.
|
| 172 |
+
Align(other);
|
| 173 |
+
|
| 174 |
+
// There are two possibilities:
|
| 175 |
+
// aaaaaaaaaaa 0000 (where the 0s represent a's exponent)
|
| 176 |
+
// bbbbb 00000000
|
| 177 |
+
// ----------------
|
| 178 |
+
// ccccccccccc 0000
|
| 179 |
+
// or
|
| 180 |
+
// aaaaaaaaaa 0000
|
| 181 |
+
// bbbbbbbbb 0000000
|
| 182 |
+
// -----------------
|
| 183 |
+
// cccccccccccc 0000
|
| 184 |
+
// In both cases we might need a carry bigit.
|
| 185 |
+
|
| 186 |
+
EnsureCapacity(1 + (std::max)(BigitLength(), other.BigitLength()) - exponent_);
|
| 187 |
+
Chunk carry = 0;
|
| 188 |
+
int bigit_pos = other.exponent_ - exponent_;
|
| 189 |
+
DOUBLE_CONVERSION_ASSERT(bigit_pos >= 0);
|
| 190 |
+
for (int i = used_bigits_; i < bigit_pos; ++i) {
|
| 191 |
+
RawBigit(i) = 0;
|
| 192 |
+
}
|
| 193 |
+
for (int i = 0; i < other.used_bigits_; ++i) {
|
| 194 |
+
const Chunk my = (bigit_pos < used_bigits_) ? RawBigit(bigit_pos) : 0;
|
| 195 |
+
const Chunk sum = my + other.RawBigit(i) + carry;
|
| 196 |
+
RawBigit(bigit_pos) = sum & kBigitMask;
|
| 197 |
+
carry = sum >> kBigitSize;
|
| 198 |
+
++bigit_pos;
|
| 199 |
+
}
|
| 200 |
+
while (carry != 0) {
|
| 201 |
+
const Chunk my = (bigit_pos < used_bigits_) ? RawBigit(bigit_pos) : 0;
|
| 202 |
+
const Chunk sum = my + carry;
|
| 203 |
+
RawBigit(bigit_pos) = sum & kBigitMask;
|
| 204 |
+
carry = sum >> kBigitSize;
|
| 205 |
+
++bigit_pos;
|
| 206 |
+
}
|
| 207 |
+
used_bigits_ = static_cast<int16_t>(std::max(bigit_pos, static_cast<int>(used_bigits_)));
|
| 208 |
+
DOUBLE_CONVERSION_ASSERT(IsClamped());
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
void Bignum::SubtractBignum(const Bignum& other) {
|
| 213 |
+
DOUBLE_CONVERSION_ASSERT(IsClamped());
|
| 214 |
+
DOUBLE_CONVERSION_ASSERT(other.IsClamped());
|
| 215 |
+
// We require this to be bigger than other.
|
| 216 |
+
DOUBLE_CONVERSION_ASSERT(LessEqual(other, *this));
|
| 217 |
+
|
| 218 |
+
Align(other);
|
| 219 |
+
|
| 220 |
+
const int offset = other.exponent_ - exponent_;
|
| 221 |
+
Chunk borrow = 0;
|
| 222 |
+
int i;
|
| 223 |
+
for (i = 0; i < other.used_bigits_; ++i) {
|
| 224 |
+
DOUBLE_CONVERSION_ASSERT((borrow == 0) || (borrow == 1));
|
| 225 |
+
const Chunk difference = RawBigit(i + offset) - other.RawBigit(i) - borrow;
|
| 226 |
+
RawBigit(i + offset) = difference & kBigitMask;
|
| 227 |
+
borrow = difference >> (kChunkSize - 1);
|
| 228 |
+
}
|
| 229 |
+
while (borrow != 0) {
|
| 230 |
+
const Chunk difference = RawBigit(i + offset) - borrow;
|
| 231 |
+
RawBigit(i + offset) = difference & kBigitMask;
|
| 232 |
+
borrow = difference >> (kChunkSize - 1);
|
| 233 |
+
++i;
|
| 234 |
+
}
|
| 235 |
+
Clamp();
|
| 236 |
+
}
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
void Bignum::ShiftLeft(const int shift_amount) {
|
| 240 |
+
if (used_bigits_ == 0) {
|
| 241 |
+
return;
|
| 242 |
+
}
|
| 243 |
+
exponent_ += static_cast<int16_t>(shift_amount / kBigitSize);
|
| 244 |
+
const int local_shift = shift_amount % kBigitSize;
|
| 245 |
+
EnsureCapacity(used_bigits_ + 1);
|
| 246 |
+
BigitsShiftLeft(local_shift);
|
| 247 |
+
}
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
void Bignum::MultiplyByUInt32(const uint32_t factor) {
|
| 251 |
+
if (factor == 1) {
|
| 252 |
+
return;
|
| 253 |
+
}
|
| 254 |
+
if (factor == 0) {
|
| 255 |
+
Zero();
|
| 256 |
+
return;
|
| 257 |
+
}
|
| 258 |
+
if (used_bigits_ == 0) {
|
| 259 |
+
return;
|
| 260 |
+
}
|
| 261 |
+
// The product of a bigit with the factor is of size kBigitSize + 32.
|
| 262 |
+
// Assert that this number + 1 (for the carry) fits into double chunk.
|
| 263 |
+
DOUBLE_CONVERSION_ASSERT(kDoubleChunkSize >= kBigitSize + 32 + 1);
|
| 264 |
+
DoubleChunk carry = 0;
|
| 265 |
+
for (int i = 0; i < used_bigits_; ++i) {
|
| 266 |
+
const DoubleChunk product = static_cast<DoubleChunk>(factor) * RawBigit(i) + carry;
|
| 267 |
+
RawBigit(i) = static_cast<Chunk>(product & kBigitMask);
|
| 268 |
+
carry = (product >> kBigitSize);
|
| 269 |
+
}
|
| 270 |
+
while (carry != 0) {
|
| 271 |
+
EnsureCapacity(used_bigits_ + 1);
|
| 272 |
+
RawBigit(used_bigits_) = carry & kBigitMask;
|
| 273 |
+
used_bigits_++;
|
| 274 |
+
carry >>= kBigitSize;
|
| 275 |
+
}
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
void Bignum::MultiplyByUInt64(const uint64_t factor) {
|
| 280 |
+
if (factor == 1) {
|
| 281 |
+
return;
|
| 282 |
+
}
|
| 283 |
+
if (factor == 0) {
|
| 284 |
+
Zero();
|
| 285 |
+
return;
|
| 286 |
+
}
|
| 287 |
+
if (used_bigits_ == 0) {
|
| 288 |
+
return;
|
| 289 |
+
}
|
| 290 |
+
DOUBLE_CONVERSION_ASSERT(kBigitSize < 32);
|
| 291 |
+
uint64_t carry = 0;
|
| 292 |
+
const uint64_t low = factor & 0xFFFFFFFF;
|
| 293 |
+
const uint64_t high = factor >> 32;
|
| 294 |
+
for (int i = 0; i < used_bigits_; ++i) {
|
| 295 |
+
const uint64_t product_low = low * RawBigit(i);
|
| 296 |
+
const uint64_t product_high = high * RawBigit(i);
|
| 297 |
+
const uint64_t tmp = (carry & kBigitMask) + product_low;
|
| 298 |
+
RawBigit(i) = tmp & kBigitMask;
|
| 299 |
+
carry = (carry >> kBigitSize) + (tmp >> kBigitSize) +
|
| 300 |
+
(product_high << (32 - kBigitSize));
|
| 301 |
+
}
|
| 302 |
+
while (carry != 0) {
|
| 303 |
+
EnsureCapacity(used_bigits_ + 1);
|
| 304 |
+
RawBigit(used_bigits_) = carry & kBigitMask;
|
| 305 |
+
used_bigits_++;
|
| 306 |
+
carry >>= kBigitSize;
|
| 307 |
+
}
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
|
| 311 |
+
void Bignum::MultiplyByPowerOfTen(const int exponent) {
|
| 312 |
+
static const uint64_t kFive27 = DOUBLE_CONVERSION_UINT64_2PART_C(0x6765c793, fa10079d);
|
| 313 |
+
static const uint16_t kFive1 = 5;
|
| 314 |
+
static const uint16_t kFive2 = kFive1 * 5;
|
| 315 |
+
static const uint16_t kFive3 = kFive2 * 5;
|
| 316 |
+
static const uint16_t kFive4 = kFive3 * 5;
|
| 317 |
+
static const uint16_t kFive5 = kFive4 * 5;
|
| 318 |
+
static const uint16_t kFive6 = kFive5 * 5;
|
| 319 |
+
static const uint32_t kFive7 = kFive6 * 5;
|
| 320 |
+
static const uint32_t kFive8 = kFive7 * 5;
|
| 321 |
+
static const uint32_t kFive9 = kFive8 * 5;
|
| 322 |
+
static const uint32_t kFive10 = kFive9 * 5;
|
| 323 |
+
static const uint32_t kFive11 = kFive10 * 5;
|
| 324 |
+
static const uint32_t kFive12 = kFive11 * 5;
|
| 325 |
+
static const uint32_t kFive13 = kFive12 * 5;
|
| 326 |
+
static const uint32_t kFive1_to_12[] =
|
| 327 |
+
{ kFive1, kFive2, kFive3, kFive4, kFive5, kFive6,
|
| 328 |
+
kFive7, kFive8, kFive9, kFive10, kFive11, kFive12 };
|
| 329 |
+
|
| 330 |
+
DOUBLE_CONVERSION_ASSERT(exponent >= 0);
|
| 331 |
+
|
| 332 |
+
if (exponent == 0) {
|
| 333 |
+
return;
|
| 334 |
+
}
|
| 335 |
+
if (used_bigits_ == 0) {
|
| 336 |
+
return;
|
| 337 |
+
}
|
| 338 |
+
// We shift by exponent at the end just before returning.
|
| 339 |
+
int remaining_exponent = exponent;
|
| 340 |
+
while (remaining_exponent >= 27) {
|
| 341 |
+
MultiplyByUInt64(kFive27);
|
| 342 |
+
remaining_exponent -= 27;
|
| 343 |
+
}
|
| 344 |
+
while (remaining_exponent >= 13) {
|
| 345 |
+
MultiplyByUInt32(kFive13);
|
| 346 |
+
remaining_exponent -= 13;
|
| 347 |
+
}
|
| 348 |
+
if (remaining_exponent > 0) {
|
| 349 |
+
MultiplyByUInt32(kFive1_to_12[remaining_exponent - 1]);
|
| 350 |
+
}
|
| 351 |
+
ShiftLeft(exponent);
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
void Bignum::Square() {
|
| 356 |
+
DOUBLE_CONVERSION_ASSERT(IsClamped());
|
| 357 |
+
const int product_length = 2 * used_bigits_;
|
| 358 |
+
EnsureCapacity(product_length);
|
| 359 |
+
|
| 360 |
+
// Comba multiplication: compute each column separately.
|
| 361 |
+
// Example: r = a2a1a0 * b2b1b0.
|
| 362 |
+
// r = 1 * a0b0 +
|
| 363 |
+
// 10 * (a1b0 + a0b1) +
|
| 364 |
+
// 100 * (a2b0 + a1b1 + a0b2) +
|
| 365 |
+
// 1000 * (a2b1 + a1b2) +
|
| 366 |
+
// 10000 * a2b2
|
| 367 |
+
//
|
| 368 |
+
// In the worst case we have to accumulate nb-digits products of digit*digit.
|
| 369 |
+
//
|
| 370 |
+
// Assert that the additional number of bits in a DoubleChunk are enough to
|
| 371 |
+
// sum up used_digits of Bigit*Bigit.
|
| 372 |
+
if ((1 << (2 * (kChunkSize - kBigitSize))) <= used_bigits_) {
|
| 373 |
+
DOUBLE_CONVERSION_UNIMPLEMENTED();
|
| 374 |
+
}
|
| 375 |
+
DoubleChunk accumulator = 0;
|
| 376 |
+
// First shift the digits so we don't overwrite them.
|
| 377 |
+
const int copy_offset = used_bigits_;
|
| 378 |
+
for (int i = 0; i < used_bigits_; ++i) {
|
| 379 |
+
RawBigit(copy_offset + i) = RawBigit(i);
|
| 380 |
+
}
|
| 381 |
+
// We have two loops to avoid some 'if's in the loop.
|
| 382 |
+
for (int i = 0; i < used_bigits_; ++i) {
|
| 383 |
+
// Process temporary digit i with power i.
|
| 384 |
+
// The sum of the two indices must be equal to i.
|
| 385 |
+
int bigit_index1 = i;
|
| 386 |
+
int bigit_index2 = 0;
|
| 387 |
+
// Sum all of the sub-products.
|
| 388 |
+
while (bigit_index1 >= 0) {
|
| 389 |
+
const Chunk chunk1 = RawBigit(copy_offset + bigit_index1);
|
| 390 |
+
const Chunk chunk2 = RawBigit(copy_offset + bigit_index2);
|
| 391 |
+
accumulator += static_cast<DoubleChunk>(chunk1) * chunk2;
|
| 392 |
+
bigit_index1--;
|
| 393 |
+
bigit_index2++;
|
| 394 |
+
}
|
| 395 |
+
RawBigit(i) = static_cast<Chunk>(accumulator) & kBigitMask;
|
| 396 |
+
accumulator >>= kBigitSize;
|
| 397 |
+
}
|
| 398 |
+
for (int i = used_bigits_; i < product_length; ++i) {
|
| 399 |
+
int bigit_index1 = used_bigits_ - 1;
|
| 400 |
+
int bigit_index2 = i - bigit_index1;
|
| 401 |
+
// Invariant: sum of both indices is again equal to i.
|
| 402 |
+
// Inner loop runs 0 times on last iteration, emptying accumulator.
|
| 403 |
+
while (bigit_index2 < used_bigits_) {
|
| 404 |
+
const Chunk chunk1 = RawBigit(copy_offset + bigit_index1);
|
| 405 |
+
const Chunk chunk2 = RawBigit(copy_offset + bigit_index2);
|
| 406 |
+
accumulator += static_cast<DoubleChunk>(chunk1) * chunk2;
|
| 407 |
+
bigit_index1--;
|
| 408 |
+
bigit_index2++;
|
| 409 |
+
}
|
| 410 |
+
// The overwritten RawBigit(i) will never be read in further loop iterations,
|
| 411 |
+
// because bigit_index1 and bigit_index2 are always greater
|
| 412 |
+
// than i - used_bigits_.
|
| 413 |
+
RawBigit(i) = static_cast<Chunk>(accumulator) & kBigitMask;
|
| 414 |
+
accumulator >>= kBigitSize;
|
| 415 |
+
}
|
| 416 |
+
// Since the result was guaranteed to lie inside the number the
|
| 417 |
+
// accumulator must be 0 now.
|
| 418 |
+
DOUBLE_CONVERSION_ASSERT(accumulator == 0);
|
| 419 |
+
|
| 420 |
+
// Don't forget to update the used_digits and the exponent.
|
| 421 |
+
used_bigits_ = static_cast<int16_t>(product_length);
|
| 422 |
+
exponent_ *= 2;
|
| 423 |
+
Clamp();
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
void Bignum::AssignPowerUInt16(uint16_t base, const int power_exponent) {
|
| 428 |
+
DOUBLE_CONVERSION_ASSERT(base != 0);
|
| 429 |
+
DOUBLE_CONVERSION_ASSERT(power_exponent >= 0);
|
| 430 |
+
if (power_exponent == 0) {
|
| 431 |
+
AssignUInt16(1);
|
| 432 |
+
return;
|
| 433 |
+
}
|
| 434 |
+
Zero();
|
| 435 |
+
int shifts = 0;
|
| 436 |
+
// We expect base to be in range 2-32, and most often to be 10.
|
| 437 |
+
// It does not make much sense to implement different algorithms for counting
|
| 438 |
+
// the bits.
|
| 439 |
+
while ((base & 1) == 0) {
|
| 440 |
+
base >>= 1;
|
| 441 |
+
shifts++;
|
| 442 |
+
}
|
| 443 |
+
int bit_size = 0;
|
| 444 |
+
int tmp_base = base;
|
| 445 |
+
while (tmp_base != 0) {
|
| 446 |
+
tmp_base >>= 1;
|
| 447 |
+
bit_size++;
|
| 448 |
+
}
|
| 449 |
+
const int final_size = bit_size * power_exponent;
|
| 450 |
+
// 1 extra bigit for the shifting, and one for rounded final_size.
|
| 451 |
+
EnsureCapacity(final_size / kBigitSize + 2);
|
| 452 |
+
|
| 453 |
+
// Left to Right exponentiation.
|
| 454 |
+
int mask = 1;
|
| 455 |
+
while (power_exponent >= mask) mask <<= 1;
|
| 456 |
+
|
| 457 |
+
// The mask is now pointing to the bit above the most significant 1-bit of
|
| 458 |
+
// power_exponent.
|
| 459 |
+
// Get rid of first 1-bit;
|
| 460 |
+
mask >>= 2;
|
| 461 |
+
uint64_t this_value = base;
|
| 462 |
+
|
| 463 |
+
bool delayed_multiplication = false;
|
| 464 |
+
const uint64_t max_32bits = 0xFFFFFFFF;
|
| 465 |
+
while (mask != 0 && this_value <= max_32bits) {
|
| 466 |
+
this_value = this_value * this_value;
|
| 467 |
+
// Verify that there is enough space in this_value to perform the
|
| 468 |
+
// multiplication. The first bit_size bits must be 0.
|
| 469 |
+
if ((power_exponent & mask) != 0) {
|
| 470 |
+
DOUBLE_CONVERSION_ASSERT(bit_size > 0);
|
| 471 |
+
const uint64_t base_bits_mask =
|
| 472 |
+
~((static_cast<uint64_t>(1) << (64 - bit_size)) - 1);
|
| 473 |
+
const bool high_bits_zero = (this_value & base_bits_mask) == 0;
|
| 474 |
+
if (high_bits_zero) {
|
| 475 |
+
this_value *= base;
|
| 476 |
+
} else {
|
| 477 |
+
delayed_multiplication = true;
|
| 478 |
+
}
|
| 479 |
+
}
|
| 480 |
+
mask >>= 1;
|
| 481 |
+
}
|
| 482 |
+
AssignUInt64(this_value);
|
| 483 |
+
if (delayed_multiplication) {
|
| 484 |
+
MultiplyByUInt32(base);
|
| 485 |
+
}
|
| 486 |
+
|
| 487 |
+
// Now do the same thing as a bignum.
|
| 488 |
+
while (mask != 0) {
|
| 489 |
+
Square();
|
| 490 |
+
if ((power_exponent & mask) != 0) {
|
| 491 |
+
MultiplyByUInt32(base);
|
| 492 |
+
}
|
| 493 |
+
mask >>= 1;
|
| 494 |
+
}
|
| 495 |
+
|
| 496 |
+
// And finally add the saved shifts.
|
| 497 |
+
ShiftLeft(shifts * power_exponent);
|
| 498 |
+
}
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
// Precondition: this/other < 16bit.
|
| 502 |
+
uint16_t Bignum::DivideModuloIntBignum(const Bignum& other) {
|
| 503 |
+
DOUBLE_CONVERSION_ASSERT(IsClamped());
|
| 504 |
+
DOUBLE_CONVERSION_ASSERT(other.IsClamped());
|
| 505 |
+
DOUBLE_CONVERSION_ASSERT(other.used_bigits_ > 0);
|
| 506 |
+
|
| 507 |
+
// Easy case: if we have less digits than the divisor than the result is 0.
|
| 508 |
+
// Note: this handles the case where this == 0, too.
|
| 509 |
+
if (BigitLength() < other.BigitLength()) {
|
| 510 |
+
return 0;
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
Align(other);
|
| 514 |
+
|
| 515 |
+
uint16_t result = 0;
|
| 516 |
+
|
| 517 |
+
// Start by removing multiples of 'other' until both numbers have the same
|
| 518 |
+
// number of digits.
|
| 519 |
+
while (BigitLength() > other.BigitLength()) {
|
| 520 |
+
// This naive approach is extremely inefficient if `this` divided by other
|
| 521 |
+
// is big. This function is implemented for doubleToString where
|
| 522 |
+
// the result should be small (less than 10).
|
| 523 |
+
DOUBLE_CONVERSION_ASSERT(other.RawBigit(other.used_bigits_ - 1) >= ((1 << kBigitSize) / 16));
|
| 524 |
+
DOUBLE_CONVERSION_ASSERT(RawBigit(used_bigits_ - 1) < 0x10000);
|
| 525 |
+
// Remove the multiples of the first digit.
|
| 526 |
+
// Example this = 23 and other equals 9. -> Remove 2 multiples.
|
| 527 |
+
result += static_cast<uint16_t>(RawBigit(used_bigits_ - 1));
|
| 528 |
+
SubtractTimes(other, RawBigit(used_bigits_ - 1));
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
DOUBLE_CONVERSION_ASSERT(BigitLength() == other.BigitLength());
|
| 532 |
+
|
| 533 |
+
// Both bignums are at the same length now.
|
| 534 |
+
// Since other has more than 0 digits we know that the access to
|
| 535 |
+
// RawBigit(used_bigits_ - 1) is safe.
|
| 536 |
+
const Chunk this_bigit = RawBigit(used_bigits_ - 1);
|
| 537 |
+
const Chunk other_bigit = other.RawBigit(other.used_bigits_ - 1);
|
| 538 |
+
|
| 539 |
+
if (other.used_bigits_ == 1) {
|
| 540 |
+
// Shortcut for easy (and common) case.
|
| 541 |
+
int quotient = this_bigit / other_bigit;
|
| 542 |
+
RawBigit(used_bigits_ - 1) = this_bigit - other_bigit * quotient;
|
| 543 |
+
DOUBLE_CONVERSION_ASSERT(quotient < 0x10000);
|
| 544 |
+
result += static_cast<uint16_t>(quotient);
|
| 545 |
+
Clamp();
|
| 546 |
+
return result;
|
| 547 |
+
}
|
| 548 |
+
|
| 549 |
+
const int division_estimate = this_bigit / (other_bigit + 1);
|
| 550 |
+
DOUBLE_CONVERSION_ASSERT(division_estimate < 0x10000);
|
| 551 |
+
result += static_cast<uint16_t>(division_estimate);
|
| 552 |
+
SubtractTimes(other, division_estimate);
|
| 553 |
+
|
| 554 |
+
if (other_bigit * (division_estimate + 1) > this_bigit) {
|
| 555 |
+
// No need to even try to subtract. Even if other's remaining digits were 0
|
| 556 |
+
// another subtraction would be too much.
|
| 557 |
+
return result;
|
| 558 |
+
}
|
| 559 |
+
|
| 560 |
+
while (LessEqual(other, *this)) {
|
| 561 |
+
SubtractBignum(other);
|
| 562 |
+
result++;
|
| 563 |
+
}
|
| 564 |
+
return result;
|
| 565 |
+
}
|
| 566 |
+
|
| 567 |
+
|
| 568 |
+
template<typename S>
|
| 569 |
+
static int SizeInHexChars(S number) {
|
| 570 |
+
DOUBLE_CONVERSION_ASSERT(number > 0);
|
| 571 |
+
int result = 0;
|
| 572 |
+
while (number != 0) {
|
| 573 |
+
number >>= 4;
|
| 574 |
+
result++;
|
| 575 |
+
}
|
| 576 |
+
return result;
|
| 577 |
+
}
|
| 578 |
+
|
| 579 |
+
|
| 580 |
+
static char HexCharOfValue(const int value) {
|
| 581 |
+
DOUBLE_CONVERSION_ASSERT(0 <= value && value <= 16);
|
| 582 |
+
if (value < 10) {
|
| 583 |
+
return static_cast<char>(value + '0');
|
| 584 |
+
}
|
| 585 |
+
return static_cast<char>(value - 10 + 'A');
|
| 586 |
+
}
|
| 587 |
+
|
| 588 |
+
|
| 589 |
+
bool Bignum::ToHexString(char* buffer, const int buffer_size) const {
|
| 590 |
+
DOUBLE_CONVERSION_ASSERT(IsClamped());
|
| 591 |
+
// Each bigit must be printable as separate hex-character.
|
| 592 |
+
DOUBLE_CONVERSION_ASSERT(kBigitSize % 4 == 0);
|
| 593 |
+
static const int kHexCharsPerBigit = kBigitSize / 4;
|
| 594 |
+
|
| 595 |
+
if (used_bigits_ == 0) {
|
| 596 |
+
if (buffer_size < 2) {
|
| 597 |
+
return false;
|
| 598 |
+
}
|
| 599 |
+
buffer[0] = '0';
|
| 600 |
+
buffer[1] = '\0';
|
| 601 |
+
return true;
|
| 602 |
+
}
|
| 603 |
+
// We add 1 for the terminating '\0' character.
|
| 604 |
+
const int needed_chars = (BigitLength() - 1) * kHexCharsPerBigit +
|
| 605 |
+
SizeInHexChars(RawBigit(used_bigits_ - 1)) + 1;
|
| 606 |
+
if (needed_chars > buffer_size) {
|
| 607 |
+
return false;
|
| 608 |
+
}
|
| 609 |
+
int string_index = needed_chars - 1;
|
| 610 |
+
buffer[string_index--] = '\0';
|
| 611 |
+
for (int i = 0; i < exponent_; ++i) {
|
| 612 |
+
for (int j = 0; j < kHexCharsPerBigit; ++j) {
|
| 613 |
+
buffer[string_index--] = '0';
|
| 614 |
+
}
|
| 615 |
+
}
|
| 616 |
+
for (int i = 0; i < used_bigits_ - 1; ++i) {
|
| 617 |
+
Chunk current_bigit = RawBigit(i);
|
| 618 |
+
for (int j = 0; j < kHexCharsPerBigit; ++j) {
|
| 619 |
+
buffer[string_index--] = HexCharOfValue(current_bigit & 0xF);
|
| 620 |
+
current_bigit >>= 4;
|
| 621 |
+
}
|
| 622 |
+
}
|
| 623 |
+
// And finally the last bigit.
|
| 624 |
+
Chunk most_significant_bigit = RawBigit(used_bigits_ - 1);
|
| 625 |
+
while (most_significant_bigit != 0) {
|
| 626 |
+
buffer[string_index--] = HexCharOfValue(most_significant_bigit & 0xF);
|
| 627 |
+
most_significant_bigit >>= 4;
|
| 628 |
+
}
|
| 629 |
+
return true;
|
| 630 |
+
}
|
| 631 |
+
|
| 632 |
+
|
| 633 |
+
Bignum::Chunk Bignum::BigitOrZero(const int index) const {
|
| 634 |
+
if (index >= BigitLength()) {
|
| 635 |
+
return 0;
|
| 636 |
+
}
|
| 637 |
+
if (index < exponent_) {
|
| 638 |
+
return 0;
|
| 639 |
+
}
|
| 640 |
+
return RawBigit(index - exponent_);
|
| 641 |
+
}
|
| 642 |
+
|
| 643 |
+
|
| 644 |
+
int Bignum::Compare(const Bignum& a, const Bignum& b) {
|
| 645 |
+
DOUBLE_CONVERSION_ASSERT(a.IsClamped());
|
| 646 |
+
DOUBLE_CONVERSION_ASSERT(b.IsClamped());
|
| 647 |
+
const int bigit_length_a = a.BigitLength();
|
| 648 |
+
const int bigit_length_b = b.BigitLength();
|
| 649 |
+
if (bigit_length_a < bigit_length_b) {
|
| 650 |
+
return -1;
|
| 651 |
+
}
|
| 652 |
+
if (bigit_length_a > bigit_length_b) {
|
| 653 |
+
return +1;
|
| 654 |
+
}
|
| 655 |
+
for (int i = bigit_length_a - 1; i >= (std::min)(a.exponent_, b.exponent_); --i) {
|
| 656 |
+
const Chunk bigit_a = a.BigitOrZero(i);
|
| 657 |
+
const Chunk bigit_b = b.BigitOrZero(i);
|
| 658 |
+
if (bigit_a < bigit_b) {
|
| 659 |
+
return -1;
|
| 660 |
+
}
|
| 661 |
+
if (bigit_a > bigit_b) {
|
| 662 |
+
return +1;
|
| 663 |
+
}
|
| 664 |
+
// Otherwise they are equal up to this digit. Try the next digit.
|
| 665 |
+
}
|
| 666 |
+
return 0;
|
| 667 |
+
}
|
| 668 |
+
|
| 669 |
+
|
| 670 |
+
int Bignum::PlusCompare(const Bignum& a, const Bignum& b, const Bignum& c) {
|
| 671 |
+
DOUBLE_CONVERSION_ASSERT(a.IsClamped());
|
| 672 |
+
DOUBLE_CONVERSION_ASSERT(b.IsClamped());
|
| 673 |
+
DOUBLE_CONVERSION_ASSERT(c.IsClamped());
|
| 674 |
+
if (a.BigitLength() < b.BigitLength()) {
|
| 675 |
+
return PlusCompare(b, a, c);
|
| 676 |
+
}
|
| 677 |
+
if (a.BigitLength() + 1 < c.BigitLength()) {
|
| 678 |
+
return -1;
|
| 679 |
+
}
|
| 680 |
+
if (a.BigitLength() > c.BigitLength()) {
|
| 681 |
+
return +1;
|
| 682 |
+
}
|
| 683 |
+
// The exponent encodes 0-bigits. So if there are more 0-digits in 'a' than
|
| 684 |
+
// 'b' has digits, then the bigit-length of 'a'+'b' must be equal to the one
|
| 685 |
+
// of 'a'.
|
| 686 |
+
if (a.exponent_ >= b.BigitLength() && a.BigitLength() < c.BigitLength()) {
|
| 687 |
+
return -1;
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
Chunk borrow = 0;
|
| 691 |
+
// Starting at min_exponent all digits are == 0. So no need to compare them.
|
| 692 |
+
const int min_exponent = (std::min)((std::min)(a.exponent_, b.exponent_), c.exponent_);
|
| 693 |
+
for (int i = c.BigitLength() - 1; i >= min_exponent; --i) {
|
| 694 |
+
const Chunk chunk_a = a.BigitOrZero(i);
|
| 695 |
+
const Chunk chunk_b = b.BigitOrZero(i);
|
| 696 |
+
const Chunk chunk_c = c.BigitOrZero(i);
|
| 697 |
+
const Chunk sum = chunk_a + chunk_b;
|
| 698 |
+
if (sum > chunk_c + borrow) {
|
| 699 |
+
return +1;
|
| 700 |
+
} else {
|
| 701 |
+
borrow = chunk_c + borrow - sum;
|
| 702 |
+
if (borrow > 1) {
|
| 703 |
+
return -1;
|
| 704 |
+
}
|
| 705 |
+
borrow <<= kBigitSize;
|
| 706 |
+
}
|
| 707 |
+
}
|
| 708 |
+
if (borrow == 0) {
|
| 709 |
+
return 0;
|
| 710 |
+
}
|
| 711 |
+
return -1;
|
| 712 |
+
}
|
| 713 |
+
|
| 714 |
+
|
| 715 |
+
void Bignum::Clamp() {
|
| 716 |
+
while (used_bigits_ > 0 && RawBigit(used_bigits_ - 1) == 0) {
|
| 717 |
+
used_bigits_--;
|
| 718 |
+
}
|
| 719 |
+
if (used_bigits_ == 0) {
|
| 720 |
+
// Zero.
|
| 721 |
+
exponent_ = 0;
|
| 722 |
+
}
|
| 723 |
+
}
|
| 724 |
+
|
| 725 |
+
|
| 726 |
+
void Bignum::Align(const Bignum& other) {
|
| 727 |
+
if (exponent_ > other.exponent_) {
|
| 728 |
+
// If "X" represents a "hidden" bigit (by the exponent) then we are in the
|
| 729 |
+
// following case (a == this, b == other):
|
| 730 |
+
// a: aaaaaaXXXX or a: aaaaaXXX
|
| 731 |
+
// b: bbbbbbX b: bbbbbbbbXX
|
| 732 |
+
// We replace some of the hidden digits (X) of a with 0 digits.
|
| 733 |
+
// a: aaaaaa000X or a: aaaaa0XX
|
| 734 |
+
const int zero_bigits = exponent_ - other.exponent_;
|
| 735 |
+
EnsureCapacity(used_bigits_ + zero_bigits);
|
| 736 |
+
for (int i = used_bigits_ - 1; i >= 0; --i) {
|
| 737 |
+
RawBigit(i + zero_bigits) = RawBigit(i);
|
| 738 |
+
}
|
| 739 |
+
for (int i = 0; i < zero_bigits; ++i) {
|
| 740 |
+
RawBigit(i) = 0;
|
| 741 |
+
}
|
| 742 |
+
used_bigits_ += static_cast<int16_t>(zero_bigits);
|
| 743 |
+
exponent_ -= static_cast<int16_t>(zero_bigits);
|
| 744 |
+
|
| 745 |
+
DOUBLE_CONVERSION_ASSERT(used_bigits_ >= 0);
|
| 746 |
+
DOUBLE_CONVERSION_ASSERT(exponent_ >= 0);
|
| 747 |
+
}
|
| 748 |
+
}
|
| 749 |
+
|
| 750 |
+
|
| 751 |
+
void Bignum::BigitsShiftLeft(const int shift_amount) {
|
| 752 |
+
DOUBLE_CONVERSION_ASSERT(shift_amount < kBigitSize);
|
| 753 |
+
DOUBLE_CONVERSION_ASSERT(shift_amount >= 0);
|
| 754 |
+
Chunk carry = 0;
|
| 755 |
+
for (int i = 0; i < used_bigits_; ++i) {
|
| 756 |
+
const Chunk new_carry = RawBigit(i) >> (kBigitSize - shift_amount);
|
| 757 |
+
RawBigit(i) = ((RawBigit(i) << shift_amount) + carry) & kBigitMask;
|
| 758 |
+
carry = new_carry;
|
| 759 |
+
}
|
| 760 |
+
if (carry != 0) {
|
| 761 |
+
RawBigit(used_bigits_) = carry;
|
| 762 |
+
used_bigits_++;
|
| 763 |
+
}
|
| 764 |
+
}
|
| 765 |
+
|
| 766 |
+
|
| 767 |
+
void Bignum::SubtractTimes(const Bignum& other, const int factor) {
|
| 768 |
+
DOUBLE_CONVERSION_ASSERT(exponent_ <= other.exponent_);
|
| 769 |
+
if (factor < 3) {
|
| 770 |
+
for (int i = 0; i < factor; ++i) {
|
| 771 |
+
SubtractBignum(other);
|
| 772 |
+
}
|
| 773 |
+
return;
|
| 774 |
+
}
|
| 775 |
+
Chunk borrow = 0;
|
| 776 |
+
const int exponent_diff = other.exponent_ - exponent_;
|
| 777 |
+
for (int i = 0; i < other.used_bigits_; ++i) {
|
| 778 |
+
const DoubleChunk product = static_cast<DoubleChunk>(factor) * other.RawBigit(i);
|
| 779 |
+
const DoubleChunk remove = borrow + product;
|
| 780 |
+
const Chunk difference = RawBigit(i + exponent_diff) - (remove & kBigitMask);
|
| 781 |
+
RawBigit(i + exponent_diff) = difference & kBigitMask;
|
| 782 |
+
borrow = static_cast<Chunk>((difference >> (kChunkSize - 1)) +
|
| 783 |
+
(remove >> kBigitSize));
|
| 784 |
+
}
|
| 785 |
+
for (int i = other.used_bigits_ + exponent_diff; i < used_bigits_; ++i) {
|
| 786 |
+
if (borrow == 0) {
|
| 787 |
+
return;
|
| 788 |
+
}
|
| 789 |
+
const Chunk difference = RawBigit(i) - borrow;
|
| 790 |
+
RawBigit(i) = difference & kBigitMask;
|
| 791 |
+
borrow = difference >> (kChunkSize - 1);
|
| 792 |
+
}
|
| 793 |
+
Clamp();
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
|
| 797 |
+
} // namespace double_conversion
|
cpp-compiled/sources/double-conversion/bignum.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/cached-powers.cc
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2006-2008 the V8 project authors. All rights reserved.
|
| 2 |
+
// Redistribution and use in source and binary forms, with or without
|
| 3 |
+
// modification, are permitted provided that the following conditions are
|
| 4 |
+
// met:
|
| 5 |
+
//
|
| 6 |
+
// * Redistributions of source code must retain the above copyright
|
| 7 |
+
// notice, this list of conditions and the following disclaimer.
|
| 8 |
+
// * Redistributions in binary form must reproduce the above
|
| 9 |
+
// copyright notice, this list of conditions and the following
|
| 10 |
+
// disclaimer in the documentation and/or other materials provided
|
| 11 |
+
// with the distribution.
|
| 12 |
+
// * Neither the name of Google Inc. nor the names of its
|
| 13 |
+
// contributors may be used to endorse or promote products derived
|
| 14 |
+
// from this software without specific prior written permission.
|
| 15 |
+
//
|
| 16 |
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 17 |
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 18 |
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 19 |
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 20 |
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 21 |
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 22 |
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 23 |
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 24 |
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 25 |
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 26 |
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 |
+
|
| 28 |
+
#include <climits>
|
| 29 |
+
#include <cmath>
|
| 30 |
+
#include <cstdarg>
|
| 31 |
+
|
| 32 |
+
#include "utils.h"
|
| 33 |
+
|
| 34 |
+
#include "cached-powers.h"
|
| 35 |
+
|
| 36 |
+
namespace double_conversion {
|
| 37 |
+
|
| 38 |
+
namespace PowersOfTenCache {
|
| 39 |
+
|
| 40 |
+
struct CachedPower {
|
| 41 |
+
uint64_t significand;
|
| 42 |
+
int16_t binary_exponent;
|
| 43 |
+
int16_t decimal_exponent;
|
| 44 |
+
};
|
| 45 |
+
|
| 46 |
+
static const CachedPower kCachedPowers[] = {
|
| 47 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xfa8fd5a0, 081c0288), -1220, -348},
|
| 48 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xbaaee17f, a23ebf76), -1193, -340},
|
| 49 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x8b16fb20, 3055ac76), -1166, -332},
|
| 50 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xcf42894a, 5dce35ea), -1140, -324},
|
| 51 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x9a6bb0aa, 55653b2d), -1113, -316},
|
| 52 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xe61acf03, 3d1a45df), -1087, -308},
|
| 53 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xab70fe17, c79ac6ca), -1060, -300},
|
| 54 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xff77b1fc, bebcdc4f), -1034, -292},
|
| 55 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xbe5691ef, 416bd60c), -1007, -284},
|
| 56 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x8dd01fad, 907ffc3c), -980, -276},
|
| 57 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xd3515c28, 31559a83), -954, -268},
|
| 58 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x9d71ac8f, ada6c9b5), -927, -260},
|
| 59 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xea9c2277, 23ee8bcb), -901, -252},
|
| 60 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xaecc4991, 4078536d), -874, -244},
|
| 61 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x823c1279, 5db6ce57), -847, -236},
|
| 62 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xc2109436, 4dfb5637), -821, -228},
|
| 63 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x9096ea6f, 3848984f), -794, -220},
|
| 64 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xd77485cb, 25823ac7), -768, -212},
|
| 65 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xa086cfcd, 97bf97f4), -741, -204},
|
| 66 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xef340a98, 172aace5), -715, -196},
|
| 67 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xb23867fb, 2a35b28e), -688, -188},
|
| 68 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x84c8d4df, d2c63f3b), -661, -180},
|
| 69 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xc5dd4427, 1ad3cdba), -635, -172},
|
| 70 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x936b9fce, bb25c996), -608, -164},
|
| 71 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xdbac6c24, 7d62a584), -582, -156},
|
| 72 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xa3ab6658, 0d5fdaf6), -555, -148},
|
| 73 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xf3e2f893, dec3f126), -529, -140},
|
| 74 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xb5b5ada8, aaff80b8), -502, -132},
|
| 75 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x87625f05, 6c7c4a8b), -475, -124},
|
| 76 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xc9bcff60, 34c13053), -449, -116},
|
| 77 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x964e858c, 91ba2655), -422, -108},
|
| 78 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xdff97724, 70297ebd), -396, -100},
|
| 79 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xa6dfbd9f, b8e5b88f), -369, -92},
|
| 80 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xf8a95fcf, 88747d94), -343, -84},
|
| 81 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xb9447093, 8fa89bcf), -316, -76},
|
| 82 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x8a08f0f8, bf0f156b), -289, -68},
|
| 83 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xcdb02555, 653131b6), -263, -60},
|
| 84 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x993fe2c6, d07b7fac), -236, -52},
|
| 85 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xe45c10c4, 2a2b3b06), -210, -44},
|
| 86 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xaa242499, 697392d3), -183, -36},
|
| 87 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xfd87b5f2, 8300ca0e), -157, -28},
|
| 88 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xbce50864, 92111aeb), -130, -20},
|
| 89 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x8cbccc09, 6f5088cc), -103, -12},
|
| 90 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xd1b71758, e219652c), -77, -4},
|
| 91 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x9c400000, 00000000), -50, 4},
|
| 92 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xe8d4a510, 00000000), -24, 12},
|
| 93 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xad78ebc5, ac620000), 3, 20},
|
| 94 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x813f3978, f8940984), 30, 28},
|
| 95 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xc097ce7b, c90715b3), 56, 36},
|
| 96 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x8f7e32ce, 7bea5c70), 83, 44},
|
| 97 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xd5d238a4, abe98068), 109, 52},
|
| 98 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x9f4f2726, 179a2245), 136, 60},
|
| 99 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xed63a231, d4c4fb27), 162, 68},
|
| 100 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xb0de6538, 8cc8ada8), 189, 76},
|
| 101 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x83c7088e, 1aab65db), 216, 84},
|
| 102 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xc45d1df9, 42711d9a), 242, 92},
|
| 103 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x924d692c, a61be758), 269, 100},
|
| 104 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xda01ee64, 1a708dea), 295, 108},
|
| 105 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xa26da399, 9aef774a), 322, 116},
|
| 106 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xf209787b, b47d6b85), 348, 124},
|
| 107 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xb454e4a1, 79dd1877), 375, 132},
|
| 108 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x865b8692, 5b9bc5c2), 402, 140},
|
| 109 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xc83553c5, c8965d3d), 428, 148},
|
| 110 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x952ab45c, fa97a0b3), 455, 156},
|
| 111 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xde469fbd, 99a05fe3), 481, 164},
|
| 112 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xa59bc234, db398c25), 508, 172},
|
| 113 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xf6c69a72, a3989f5c), 534, 180},
|
| 114 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xb7dcbf53, 54e9bece), 561, 188},
|
| 115 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x88fcf317, f22241e2), 588, 196},
|
| 116 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xcc20ce9b, d35c78a5), 614, 204},
|
| 117 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x98165af3, 7b2153df), 641, 212},
|
| 118 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xe2a0b5dc, 971f303a), 667, 220},
|
| 119 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xa8d9d153, 5ce3b396), 694, 228},
|
| 120 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xfb9b7cd9, a4a7443c), 720, 236},
|
| 121 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xbb764c4c, a7a44410), 747, 244},
|
| 122 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x8bab8eef, b6409c1a), 774, 252},
|
| 123 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xd01fef10, a657842c), 800, 260},
|
| 124 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x9b10a4e5, e9913129), 827, 268},
|
| 125 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xe7109bfb, a19c0c9d), 853, 276},
|
| 126 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xac2820d9, 623bf429), 880, 284},
|
| 127 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x80444b5e, 7aa7cf85), 907, 292},
|
| 128 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xbf21e440, 03acdd2d), 933, 300},
|
| 129 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x8e679c2f, 5e44ff8f), 960, 308},
|
| 130 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xd433179d, 9c8cb841), 986, 316},
|
| 131 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0x9e19db92, b4e31ba9), 1013, 324},
|
| 132 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xeb96bf6e, badf77d9), 1039, 332},
|
| 133 |
+
{DOUBLE_CONVERSION_UINT64_2PART_C(0xaf87023b, 9bf0ee6b), 1066, 340},
|
| 134 |
+
};
|
| 135 |
+
|
| 136 |
+
static const int kCachedPowersOffset = 348; // -1 * the first decimal_exponent.
|
| 137 |
+
static const double kD_1_LOG2_10 = 0.30102999566398114; // 1 / lg(10)
|
| 138 |
+
|
| 139 |
+
void GetCachedPowerForBinaryExponentRange(
|
| 140 |
+
int min_exponent,
|
| 141 |
+
int max_exponent,
|
| 142 |
+
DiyFp* power,
|
| 143 |
+
int* decimal_exponent) {
|
| 144 |
+
int kQ = DiyFp::kSignificandSize;
|
| 145 |
+
double k = ceil((min_exponent + kQ - 1) * kD_1_LOG2_10);
|
| 146 |
+
int foo = kCachedPowersOffset;
|
| 147 |
+
int index =
|
| 148 |
+
(foo + static_cast<int>(k) - 1) / kDecimalExponentDistance + 1;
|
| 149 |
+
DOUBLE_CONVERSION_ASSERT(0 <= index && index < static_cast<int>(DOUBLE_CONVERSION_ARRAY_SIZE(kCachedPowers)));
|
| 150 |
+
CachedPower cached_power = kCachedPowers[index];
|
| 151 |
+
DOUBLE_CONVERSION_ASSERT(min_exponent <= cached_power.binary_exponent);
|
| 152 |
+
(void) max_exponent; // Mark variable as used.
|
| 153 |
+
DOUBLE_CONVERSION_ASSERT(cached_power.binary_exponent <= max_exponent);
|
| 154 |
+
*decimal_exponent = cached_power.decimal_exponent;
|
| 155 |
+
*power = DiyFp(cached_power.significand, cached_power.binary_exponent);
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
void GetCachedPowerForDecimalExponent(int requested_exponent,
|
| 160 |
+
DiyFp* power,
|
| 161 |
+
int* found_exponent) {
|
| 162 |
+
DOUBLE_CONVERSION_ASSERT(kMinDecimalExponent <= requested_exponent);
|
| 163 |
+
DOUBLE_CONVERSION_ASSERT(requested_exponent < kMaxDecimalExponent + kDecimalExponentDistance);
|
| 164 |
+
int index =
|
| 165 |
+
(requested_exponent + kCachedPowersOffset) / kDecimalExponentDistance;
|
| 166 |
+
CachedPower cached_power = kCachedPowers[index];
|
| 167 |
+
*power = DiyFp(cached_power.significand, cached_power.binary_exponent);
|
| 168 |
+
*found_exponent = cached_power.decimal_exponent;
|
| 169 |
+
DOUBLE_CONVERSION_ASSERT(*found_exponent <= requested_exponent);
|
| 170 |
+
DOUBLE_CONVERSION_ASSERT(requested_exponent < *found_exponent + kDecimalExponentDistance);
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
} // namespace PowersOfTenCache
|
| 174 |
+
|
| 175 |
+
} // namespace double_conversion
|
cpp-compiled/sources/double-conversion/cached-powers.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/cctest.cc
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2008 the V8 project authors. All rights reserved.
|
| 2 |
+
// Redistribution and use in source and binary forms, with or without
|
| 3 |
+
// modification, are permitted provided that the following conditions are
|
| 4 |
+
// met:
|
| 5 |
+
//
|
| 6 |
+
// * Redistributions of source code must retain the above copyright
|
| 7 |
+
// notice, this list of conditions and the following disclaimer.
|
| 8 |
+
// * Redistributions in binary form must reproduce the above
|
| 9 |
+
// copyright notice, this list of conditions and the following
|
| 10 |
+
// disclaimer in the documentation and/or other materials provided
|
| 11 |
+
// with the distribution.
|
| 12 |
+
// * Neither the name of Google Inc. nor the names of its
|
| 13 |
+
// contributors may be used to endorse or promote products derived
|
| 14 |
+
// from this software without specific prior written permission.
|
| 15 |
+
//
|
| 16 |
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 17 |
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 18 |
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 19 |
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 20 |
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 21 |
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 22 |
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 23 |
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 24 |
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 25 |
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 26 |
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 |
+
|
| 28 |
+
#include "cctest.h"
|
| 29 |
+
#include <stdio.h>
|
| 30 |
+
#include <stdlib.h>
|
| 31 |
+
#include <string.h>
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
CcTest* CcTest::last_ = NULL;
|
| 35 |
+
|
| 36 |
+
// The windows compiler doesn't like to use `strdup`, and claims it's a
|
| 37 |
+
// deprecated name.
|
| 38 |
+
// For simplicity just implement it ourselves.
|
| 39 |
+
static char* Strdup(const char* str) {
|
| 40 |
+
size_t len = strlen(str);
|
| 41 |
+
char* result = reinterpret_cast<char*>(malloc(len + 1));
|
| 42 |
+
memcpy(result, str, len + 1);
|
| 43 |
+
return result;
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
CcTest::CcTest(TestFunction* callback, const char* test_file,
|
| 47 |
+
const char* test_name, const char* test_dependency,
|
| 48 |
+
bool test_is_enabled)
|
| 49 |
+
: callback_(callback), name_(test_name), dependency_(test_dependency),
|
| 50 |
+
prev_(last_) {
|
| 51 |
+
// Find the base name of this test (const_cast required on Windows).
|
| 52 |
+
char *basename = strrchr(const_cast<char *>(test_file), '/');
|
| 53 |
+
if (!basename) {
|
| 54 |
+
basename = strrchr(const_cast<char *>(test_file), '\\');
|
| 55 |
+
}
|
| 56 |
+
if (!basename) {
|
| 57 |
+
basename = Strdup(test_file);
|
| 58 |
+
} else {
|
| 59 |
+
basename = Strdup(basename + 1);
|
| 60 |
+
}
|
| 61 |
+
// Drop the extension, if there is one.
|
| 62 |
+
char *extension = strrchr(basename, '.');
|
| 63 |
+
if (extension) *extension = 0;
|
| 64 |
+
// Install this test in the list of tests
|
| 65 |
+
file_ = basename;
|
| 66 |
+
enabled_ = test_is_enabled;
|
| 67 |
+
prev_ = last_;
|
| 68 |
+
last_ = this;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
static void PrintTestList(CcTest* current) {
|
| 73 |
+
if (current == NULL) return;
|
| 74 |
+
PrintTestList(current->prev());
|
| 75 |
+
if (current->dependency() != NULL) {
|
| 76 |
+
printf("%s/%s<%s\n",
|
| 77 |
+
current->file(), current->name(), current->dependency());
|
| 78 |
+
} else {
|
| 79 |
+
printf("%s/%s<\n", current->file(), current->name());
|
| 80 |
+
}
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
int main(int argc, char* argv[]) {
|
| 85 |
+
int tests_run = 0;
|
| 86 |
+
bool print_run_count = true;
|
| 87 |
+
if (argc == 1) {
|
| 88 |
+
// Just run all the tests.
|
| 89 |
+
CcTest* test = CcTest::last();
|
| 90 |
+
while (test != NULL) {
|
| 91 |
+
if (test->enabled()) {
|
| 92 |
+
test->Run();
|
| 93 |
+
tests_run++;
|
| 94 |
+
}
|
| 95 |
+
test = test->prev();
|
| 96 |
+
}
|
| 97 |
+
}
|
| 98 |
+
for (int i = 1; i < argc; i++) {
|
| 99 |
+
char* arg = argv[i];
|
| 100 |
+
if (strcmp(arg, "--list") == 0) {
|
| 101 |
+
PrintTestList(CcTest::last());
|
| 102 |
+
print_run_count = false;
|
| 103 |
+
|
| 104 |
+
} else {
|
| 105 |
+
char* arg_copy = Strdup(arg);
|
| 106 |
+
char* testname = strchr(arg_copy, '/');
|
| 107 |
+
if (testname) {
|
| 108 |
+
// Split the string in two by nulling the slash and then run
|
| 109 |
+
// exact matches.
|
| 110 |
+
*testname = 0;
|
| 111 |
+
char* file = arg_copy;
|
| 112 |
+
char* name = testname + 1;
|
| 113 |
+
CcTest* test = CcTest::last();
|
| 114 |
+
while (test != NULL) {
|
| 115 |
+
if (test->enabled()
|
| 116 |
+
&& strcmp(test->file(), file) == 0
|
| 117 |
+
&& strcmp(test->name(), name) == 0) {
|
| 118 |
+
test->Run();
|
| 119 |
+
tests_run++;
|
| 120 |
+
}
|
| 121 |
+
test = test->prev();
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
} else {
|
| 125 |
+
// Run all tests with the specified file or test name.
|
| 126 |
+
char* file_or_name = arg_copy;
|
| 127 |
+
CcTest* test = CcTest::last();
|
| 128 |
+
while (test != NULL) {
|
| 129 |
+
if (test->enabled()
|
| 130 |
+
&& (strcmp(test->file(), file_or_name) == 0
|
| 131 |
+
|| strcmp(test->name(), file_or_name) == 0)) {
|
| 132 |
+
test->Run();
|
| 133 |
+
tests_run++;
|
| 134 |
+
}
|
| 135 |
+
test = test->prev();
|
| 136 |
+
}
|
| 137 |
+
}
|
| 138 |
+
free(arg_copy);
|
| 139 |
+
}
|
| 140 |
+
}
|
| 141 |
+
if (print_run_count && tests_run != 1)
|
| 142 |
+
printf("Ran %i tests.\n", tests_run);
|
| 143 |
+
return 0;
|
| 144 |
+
}
|
cpp-compiled/sources/double-conversion/double-to-string.cc
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2010 the V8 project authors. All rights reserved.
|
| 2 |
+
// Redistribution and use in source and binary forms, with or without
|
| 3 |
+
// modification, are permitted provided that the following conditions are
|
| 4 |
+
// met:
|
| 5 |
+
//
|
| 6 |
+
// * Redistributions of source code must retain the above copyright
|
| 7 |
+
// notice, this list of conditions and the following disclaimer.
|
| 8 |
+
// * Redistributions in binary form must reproduce the above
|
| 9 |
+
// copyright notice, this list of conditions and the following
|
| 10 |
+
// disclaimer in the documentation and/or other materials provided
|
| 11 |
+
// with the distribution.
|
| 12 |
+
// * Neither the name of Google Inc. nor the names of its
|
| 13 |
+
// contributors may be used to endorse or promote products derived
|
| 14 |
+
// from this software without specific prior written permission.
|
| 15 |
+
//
|
| 16 |
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 17 |
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 18 |
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 19 |
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 20 |
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 21 |
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 22 |
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 23 |
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 24 |
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 25 |
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 26 |
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 |
+
|
| 28 |
+
#include <algorithm>
|
| 29 |
+
#include <climits>
|
| 30 |
+
#include <cmath>
|
| 31 |
+
|
| 32 |
+
#include "double-to-string.h"
|
| 33 |
+
|
| 34 |
+
#include "bignum-dtoa.h"
|
| 35 |
+
#include "fast-dtoa.h"
|
| 36 |
+
#include "fixed-dtoa.h"
|
| 37 |
+
#include "ieee.h"
|
| 38 |
+
#include "utils.h"
|
| 39 |
+
|
| 40 |
+
namespace double_conversion {
|
| 41 |
+
|
| 42 |
+
const DoubleToStringConverter& DoubleToStringConverter::EcmaScriptConverter() {
|
| 43 |
+
int flags = UNIQUE_ZERO | EMIT_POSITIVE_EXPONENT_SIGN;
|
| 44 |
+
static DoubleToStringConverter converter(flags,
|
| 45 |
+
"Infinity",
|
| 46 |
+
"NaN",
|
| 47 |
+
'e',
|
| 48 |
+
-6, 21,
|
| 49 |
+
6, 0);
|
| 50 |
+
return converter;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
bool DoubleToStringConverter::HandleSpecialValues(
|
| 55 |
+
double value,
|
| 56 |
+
StringBuilder* result_builder) const {
|
| 57 |
+
Double double_inspect(value);
|
| 58 |
+
if (double_inspect.IsInfinite()) {
|
| 59 |
+
if (infinity_symbol_ == DOUBLE_CONVERSION_NULLPTR) return false;
|
| 60 |
+
if (value < 0) {
|
| 61 |
+
result_builder->AddCharacter('-');
|
| 62 |
+
}
|
| 63 |
+
result_builder->AddString(infinity_symbol_);
|
| 64 |
+
return true;
|
| 65 |
+
}
|
| 66 |
+
if (double_inspect.IsNan()) {
|
| 67 |
+
if (nan_symbol_ == DOUBLE_CONVERSION_NULLPTR) return false;
|
| 68 |
+
result_builder->AddString(nan_symbol_);
|
| 69 |
+
return true;
|
| 70 |
+
}
|
| 71 |
+
return false;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
void DoubleToStringConverter::CreateExponentialRepresentation(
|
| 76 |
+
const char* decimal_digits,
|
| 77 |
+
int length,
|
| 78 |
+
int exponent,
|
| 79 |
+
StringBuilder* result_builder) const {
|
| 80 |
+
DOUBLE_CONVERSION_ASSERT(length != 0);
|
| 81 |
+
result_builder->AddCharacter(decimal_digits[0]);
|
| 82 |
+
if (length == 1) {
|
| 83 |
+
if ((flags_ & EMIT_TRAILING_DECIMAL_POINT_IN_EXPONENTIAL) != 0) {
|
| 84 |
+
result_builder->AddCharacter('.');
|
| 85 |
+
if ((flags_ & EMIT_TRAILING_ZERO_AFTER_POINT_IN_EXPONENTIAL) != 0) {
|
| 86 |
+
result_builder->AddCharacter('0');
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
} else {
|
| 90 |
+
result_builder->AddCharacter('.');
|
| 91 |
+
result_builder->AddSubstring(&decimal_digits[1], length-1);
|
| 92 |
+
}
|
| 93 |
+
result_builder->AddCharacter(exponent_character_);
|
| 94 |
+
if (exponent < 0) {
|
| 95 |
+
result_builder->AddCharacter('-');
|
| 96 |
+
exponent = -exponent;
|
| 97 |
+
} else {
|
| 98 |
+
if ((flags_ & EMIT_POSITIVE_EXPONENT_SIGN) != 0) {
|
| 99 |
+
result_builder->AddCharacter('+');
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
+
DOUBLE_CONVERSION_ASSERT(exponent < 1e4);
|
| 103 |
+
// Changing this constant requires updating the comment of DoubleToStringConverter constructor
|
| 104 |
+
const int kMaxExponentLength = 5;
|
| 105 |
+
char buffer[kMaxExponentLength + 1];
|
| 106 |
+
buffer[kMaxExponentLength] = '\0';
|
| 107 |
+
int first_char_pos = kMaxExponentLength;
|
| 108 |
+
if (exponent == 0) {
|
| 109 |
+
buffer[--first_char_pos] = '0';
|
| 110 |
+
} else {
|
| 111 |
+
while (exponent > 0) {
|
| 112 |
+
buffer[--first_char_pos] = '0' + (exponent % 10);
|
| 113 |
+
exponent /= 10;
|
| 114 |
+
}
|
| 115 |
+
}
|
| 116 |
+
// Add prefix '0' to make exponent width >= min(min_exponent_with_, kMaxExponentLength)
|
| 117 |
+
// For example: convert 1e+9 -> 1e+09, if min_exponent_with_ is set to 2
|
| 118 |
+
while(kMaxExponentLength - first_char_pos < std::min(min_exponent_width_, kMaxExponentLength)) {
|
| 119 |
+
buffer[--first_char_pos] = '0';
|
| 120 |
+
}
|
| 121 |
+
result_builder->AddSubstring(&buffer[first_char_pos],
|
| 122 |
+
kMaxExponentLength - first_char_pos);
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
void DoubleToStringConverter::CreateDecimalRepresentation(
|
| 127 |
+
const char* decimal_digits,
|
| 128 |
+
int length,
|
| 129 |
+
int decimal_point,
|
| 130 |
+
int digits_after_point,
|
| 131 |
+
StringBuilder* result_builder) const {
|
| 132 |
+
// Create a representation that is padded with zeros if needed.
|
| 133 |
+
if (decimal_point <= 0) {
|
| 134 |
+
// "0.00000decimal_rep" or "0.000decimal_rep00".
|
| 135 |
+
result_builder->AddCharacter('0');
|
| 136 |
+
if (digits_after_point > 0) {
|
| 137 |
+
result_builder->AddCharacter('.');
|
| 138 |
+
result_builder->AddPadding('0', -decimal_point);
|
| 139 |
+
DOUBLE_CONVERSION_ASSERT(length <= digits_after_point - (-decimal_point));
|
| 140 |
+
result_builder->AddSubstring(decimal_digits, length);
|
| 141 |
+
int remaining_digits = digits_after_point - (-decimal_point) - length;
|
| 142 |
+
result_builder->AddPadding('0', remaining_digits);
|
| 143 |
+
}
|
| 144 |
+
} else if (decimal_point >= length) {
|
| 145 |
+
// "decimal_rep0000.00000" or "decimal_rep.0000".
|
| 146 |
+
result_builder->AddSubstring(decimal_digits, length);
|
| 147 |
+
result_builder->AddPadding('0', decimal_point - length);
|
| 148 |
+
if (digits_after_point > 0) {
|
| 149 |
+
result_builder->AddCharacter('.');
|
| 150 |
+
result_builder->AddPadding('0', digits_after_point);
|
| 151 |
+
}
|
| 152 |
+
} else {
|
| 153 |
+
// "decima.l_rep000".
|
| 154 |
+
DOUBLE_CONVERSION_ASSERT(digits_after_point > 0);
|
| 155 |
+
result_builder->AddSubstring(decimal_digits, decimal_point);
|
| 156 |
+
result_builder->AddCharacter('.');
|
| 157 |
+
DOUBLE_CONVERSION_ASSERT(length - decimal_point <= digits_after_point);
|
| 158 |
+
result_builder->AddSubstring(&decimal_digits[decimal_point],
|
| 159 |
+
length - decimal_point);
|
| 160 |
+
int remaining_digits = digits_after_point - (length - decimal_point);
|
| 161 |
+
result_builder->AddPadding('0', remaining_digits);
|
| 162 |
+
}
|
| 163 |
+
if (digits_after_point == 0) {
|
| 164 |
+
if ((flags_ & EMIT_TRAILING_DECIMAL_POINT) != 0) {
|
| 165 |
+
result_builder->AddCharacter('.');
|
| 166 |
+
}
|
| 167 |
+
if ((flags_ & EMIT_TRAILING_ZERO_AFTER_POINT) != 0) {
|
| 168 |
+
result_builder->AddCharacter('0');
|
| 169 |
+
}
|
| 170 |
+
}
|
| 171 |
+
}
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
bool DoubleToStringConverter::ToShortestIeeeNumber(
|
| 175 |
+
double value,
|
| 176 |
+
StringBuilder* result_builder,
|
| 177 |
+
DoubleToStringConverter::DtoaMode mode) const {
|
| 178 |
+
DOUBLE_CONVERSION_ASSERT(mode == SHORTEST || mode == SHORTEST_SINGLE);
|
| 179 |
+
if (Double(value).IsSpecial()) {
|
| 180 |
+
return HandleSpecialValues(value, result_builder);
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
int decimal_point;
|
| 184 |
+
bool sign;
|
| 185 |
+
const int kDecimalRepCapacity = kBase10MaximalLength + 1;
|
| 186 |
+
char decimal_rep[kDecimalRepCapacity];
|
| 187 |
+
int decimal_rep_length;
|
| 188 |
+
|
| 189 |
+
DoubleToAscii(value, mode, 0, decimal_rep, kDecimalRepCapacity,
|
| 190 |
+
&sign, &decimal_rep_length, &decimal_point);
|
| 191 |
+
|
| 192 |
+
bool unique_zero = (flags_ & UNIQUE_ZERO) != 0;
|
| 193 |
+
if (sign && (value != 0.0 || !unique_zero)) {
|
| 194 |
+
result_builder->AddCharacter('-');
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
int exponent = decimal_point - 1;
|
| 198 |
+
if ((decimal_in_shortest_low_ <= exponent) &&
|
| 199 |
+
(exponent < decimal_in_shortest_high_)) {
|
| 200 |
+
CreateDecimalRepresentation(decimal_rep, decimal_rep_length,
|
| 201 |
+
decimal_point,
|
| 202 |
+
(std::max)(0, decimal_rep_length - decimal_point),
|
| 203 |
+
result_builder);
|
| 204 |
+
} else {
|
| 205 |
+
CreateExponentialRepresentation(decimal_rep, decimal_rep_length, exponent,
|
| 206 |
+
result_builder);
|
| 207 |
+
}
|
| 208 |
+
return true;
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
|
| 212 |
+
bool DoubleToStringConverter::ToFixed(double value,
|
| 213 |
+
int requested_digits,
|
| 214 |
+
StringBuilder* result_builder) const {
|
| 215 |
+
DOUBLE_CONVERSION_ASSERT(kMaxFixedDigitsBeforePoint == 60);
|
| 216 |
+
const double kFirstNonFixed = 1e60;
|
| 217 |
+
|
| 218 |
+
if (Double(value).IsSpecial()) {
|
| 219 |
+
return HandleSpecialValues(value, result_builder);
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
if (requested_digits > kMaxFixedDigitsAfterPoint) return false;
|
| 223 |
+
if (value >= kFirstNonFixed || value <= -kFirstNonFixed) return false;
|
| 224 |
+
|
| 225 |
+
// Find a sufficiently precise decimal representation of n.
|
| 226 |
+
int decimal_point;
|
| 227 |
+
bool sign;
|
| 228 |
+
// Add space for the '\0' byte.
|
| 229 |
+
const int kDecimalRepCapacity =
|
| 230 |
+
kMaxFixedDigitsBeforePoint + kMaxFixedDigitsAfterPoint + 1;
|
| 231 |
+
char decimal_rep[kDecimalRepCapacity];
|
| 232 |
+
int decimal_rep_length;
|
| 233 |
+
DoubleToAscii(value, FIXED, requested_digits,
|
| 234 |
+
decimal_rep, kDecimalRepCapacity,
|
| 235 |
+
&sign, &decimal_rep_length, &decimal_point);
|
| 236 |
+
|
| 237 |
+
bool unique_zero = ((flags_ & UNIQUE_ZERO) != 0);
|
| 238 |
+
if (sign && (value != 0.0 || !unique_zero)) {
|
| 239 |
+
result_builder->AddCharacter('-');
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
CreateDecimalRepresentation(decimal_rep, decimal_rep_length, decimal_point,
|
| 243 |
+
requested_digits, result_builder);
|
| 244 |
+
return true;
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
bool DoubleToStringConverter::ToExponential(
|
| 249 |
+
double value,
|
| 250 |
+
int requested_digits,
|
| 251 |
+
StringBuilder* result_builder) const {
|
| 252 |
+
if (Double(value).IsSpecial()) {
|
| 253 |
+
return HandleSpecialValues(value, result_builder);
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
if (requested_digits < -1) return false;
|
| 257 |
+
if (requested_digits > kMaxExponentialDigits) return false;
|
| 258 |
+
|
| 259 |
+
int decimal_point;
|
| 260 |
+
bool sign;
|
| 261 |
+
// Add space for digit before the decimal point and the '\0' character.
|
| 262 |
+
const int kDecimalRepCapacity = kMaxExponentialDigits + 2;
|
| 263 |
+
DOUBLE_CONVERSION_ASSERT(kDecimalRepCapacity > kBase10MaximalLength);
|
| 264 |
+
char decimal_rep[kDecimalRepCapacity];
|
| 265 |
+
#ifndef NDEBUG
|
| 266 |
+
// Problem: there is an assert in StringBuilder::AddSubstring() that
|
| 267 |
+
// will pass this buffer to strlen(), and this buffer is not generally
|
| 268 |
+
// null-terminated.
|
| 269 |
+
memset(decimal_rep, 0, sizeof(decimal_rep));
|
| 270 |
+
#endif
|
| 271 |
+
int decimal_rep_length;
|
| 272 |
+
|
| 273 |
+
if (requested_digits == -1) {
|
| 274 |
+
DoubleToAscii(value, SHORTEST, 0,
|
| 275 |
+
decimal_rep, kDecimalRepCapacity,
|
| 276 |
+
&sign, &decimal_rep_length, &decimal_point);
|
| 277 |
+
} else {
|
| 278 |
+
DoubleToAscii(value, PRECISION, requested_digits + 1,
|
| 279 |
+
decimal_rep, kDecimalRepCapacity,
|
| 280 |
+
&sign, &decimal_rep_length, &decimal_point);
|
| 281 |
+
DOUBLE_CONVERSION_ASSERT(decimal_rep_length <= requested_digits + 1);
|
| 282 |
+
|
| 283 |
+
for (int i = decimal_rep_length; i < requested_digits + 1; ++i) {
|
| 284 |
+
decimal_rep[i] = '0';
|
| 285 |
+
}
|
| 286 |
+
decimal_rep_length = requested_digits + 1;
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
bool unique_zero = ((flags_ & UNIQUE_ZERO) != 0);
|
| 290 |
+
if (sign && (value != 0.0 || !unique_zero)) {
|
| 291 |
+
result_builder->AddCharacter('-');
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
int exponent = decimal_point - 1;
|
| 295 |
+
CreateExponentialRepresentation(decimal_rep,
|
| 296 |
+
decimal_rep_length,
|
| 297 |
+
exponent,
|
| 298 |
+
result_builder);
|
| 299 |
+
return true;
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
|
| 303 |
+
bool DoubleToStringConverter::ToPrecision(double value,
|
| 304 |
+
int precision,
|
| 305 |
+
StringBuilder* result_builder) const {
|
| 306 |
+
if (Double(value).IsSpecial()) {
|
| 307 |
+
return HandleSpecialValues(value, result_builder);
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
if (precision < kMinPrecisionDigits || precision > kMaxPrecisionDigits) {
|
| 311 |
+
return false;
|
| 312 |
+
}
|
| 313 |
+
|
| 314 |
+
// Find a sufficiently precise decimal representation of n.
|
| 315 |
+
int decimal_point;
|
| 316 |
+
bool sign;
|
| 317 |
+
// Add one for the terminating null character.
|
| 318 |
+
const int kDecimalRepCapacity = kMaxPrecisionDigits + 1;
|
| 319 |
+
char decimal_rep[kDecimalRepCapacity];
|
| 320 |
+
int decimal_rep_length;
|
| 321 |
+
|
| 322 |
+
DoubleToAscii(value, PRECISION, precision,
|
| 323 |
+
decimal_rep, kDecimalRepCapacity,
|
| 324 |
+
&sign, &decimal_rep_length, &decimal_point);
|
| 325 |
+
DOUBLE_CONVERSION_ASSERT(decimal_rep_length <= precision);
|
| 326 |
+
|
| 327 |
+
bool unique_zero = ((flags_ & UNIQUE_ZERO) != 0);
|
| 328 |
+
if (sign && (value != 0.0 || !unique_zero)) {
|
| 329 |
+
result_builder->AddCharacter('-');
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
// The exponent if we print the number as x.xxeyyy. That is with the
|
| 333 |
+
// decimal point after the first digit.
|
| 334 |
+
int exponent = decimal_point - 1;
|
| 335 |
+
|
| 336 |
+
int extra_zero = ((flags_ & EMIT_TRAILING_ZERO_AFTER_POINT) != 0) ? 1 : 0;
|
| 337 |
+
bool as_exponential =
|
| 338 |
+
(-decimal_point + 1 > max_leading_padding_zeroes_in_precision_mode_) ||
|
| 339 |
+
(decimal_point - precision + extra_zero >
|
| 340 |
+
max_trailing_padding_zeroes_in_precision_mode_);
|
| 341 |
+
if ((flags_ & NO_TRAILING_ZERO) != 0) {
|
| 342 |
+
// Truncate trailing zeros that occur after the decimal point (if exponential,
|
| 343 |
+
// that is everything after the first digit).
|
| 344 |
+
int stop = as_exponential ? 1 : std::max(1, decimal_point);
|
| 345 |
+
while (decimal_rep_length > stop && decimal_rep[decimal_rep_length - 1] == '0') {
|
| 346 |
+
--decimal_rep_length;
|
| 347 |
+
}
|
| 348 |
+
// Clamp precision to avoid the code below re-adding the zeros.
|
| 349 |
+
precision = std::min(precision, decimal_rep_length);
|
| 350 |
+
}
|
| 351 |
+
if (as_exponential) {
|
| 352 |
+
// Fill buffer to contain 'precision' digits.
|
| 353 |
+
// Usually the buffer is already at the correct length, but 'DoubleToAscii'
|
| 354 |
+
// is allowed to return less characters.
|
| 355 |
+
for (int i = decimal_rep_length; i < precision; ++i) {
|
| 356 |
+
decimal_rep[i] = '0';
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
CreateExponentialRepresentation(decimal_rep,
|
| 360 |
+
precision,
|
| 361 |
+
exponent,
|
| 362 |
+
result_builder);
|
| 363 |
+
} else {
|
| 364 |
+
CreateDecimalRepresentation(decimal_rep, decimal_rep_length, decimal_point,
|
| 365 |
+
(std::max)(0, precision - decimal_point),
|
| 366 |
+
result_builder);
|
| 367 |
+
}
|
| 368 |
+
return true;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
static BignumDtoaMode DtoaToBignumDtoaMode(
|
| 373 |
+
DoubleToStringConverter::DtoaMode dtoa_mode) {
|
| 374 |
+
switch (dtoa_mode) {
|
| 375 |
+
case DoubleToStringConverter::SHORTEST: return BIGNUM_DTOA_SHORTEST;
|
| 376 |
+
case DoubleToStringConverter::SHORTEST_SINGLE:
|
| 377 |
+
return BIGNUM_DTOA_SHORTEST_SINGLE;
|
| 378 |
+
case DoubleToStringConverter::FIXED: return BIGNUM_DTOA_FIXED;
|
| 379 |
+
case DoubleToStringConverter::PRECISION: return BIGNUM_DTOA_PRECISION;
|
| 380 |
+
default:
|
| 381 |
+
DOUBLE_CONVERSION_UNREACHABLE();
|
| 382 |
+
}
|
| 383 |
+
}
|
| 384 |
+
|
| 385 |
+
|
| 386 |
+
void DoubleToStringConverter::DoubleToAscii(double v,
|
| 387 |
+
DtoaMode mode,
|
| 388 |
+
int requested_digits,
|
| 389 |
+
char* buffer,
|
| 390 |
+
int buffer_length,
|
| 391 |
+
bool* sign,
|
| 392 |
+
int* length,
|
| 393 |
+
int* point) {
|
| 394 |
+
Vector<char> vector(buffer, buffer_length);
|
| 395 |
+
DOUBLE_CONVERSION_ASSERT(!Double(v).IsSpecial());
|
| 396 |
+
DOUBLE_CONVERSION_ASSERT(mode == SHORTEST || mode == SHORTEST_SINGLE || requested_digits >= 0);
|
| 397 |
+
|
| 398 |
+
if (Double(v).Sign() < 0) {
|
| 399 |
+
*sign = true;
|
| 400 |
+
v = -v;
|
| 401 |
+
} else {
|
| 402 |
+
*sign = false;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
if (mode == PRECISION && requested_digits == 0) {
|
| 406 |
+
vector[0] = '\0';
|
| 407 |
+
*length = 0;
|
| 408 |
+
return;
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
if (v == 0) {
|
| 412 |
+
vector[0] = '0';
|
| 413 |
+
vector[1] = '\0';
|
| 414 |
+
*length = 1;
|
| 415 |
+
*point = 1;
|
| 416 |
+
return;
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
bool fast_worked;
|
| 420 |
+
switch (mode) {
|
| 421 |
+
case SHORTEST:
|
| 422 |
+
fast_worked = FastDtoa(v, FAST_DTOA_SHORTEST, 0, vector, length, point);
|
| 423 |
+
break;
|
| 424 |
+
case SHORTEST_SINGLE:
|
| 425 |
+
fast_worked = FastDtoa(v, FAST_DTOA_SHORTEST_SINGLE, 0,
|
| 426 |
+
vector, length, point);
|
| 427 |
+
break;
|
| 428 |
+
case FIXED:
|
| 429 |
+
fast_worked = FastFixedDtoa(v, requested_digits, vector, length, point);
|
| 430 |
+
break;
|
| 431 |
+
case PRECISION:
|
| 432 |
+
fast_worked = FastDtoa(v, FAST_DTOA_PRECISION, requested_digits,
|
| 433 |
+
vector, length, point);
|
| 434 |
+
break;
|
| 435 |
+
default:
|
| 436 |
+
fast_worked = false;
|
| 437 |
+
DOUBLE_CONVERSION_UNREACHABLE();
|
| 438 |
+
}
|
| 439 |
+
if (fast_worked) return;
|
| 440 |
+
|
| 441 |
+
// If the fast dtoa didn't succeed use the slower bignum version.
|
| 442 |
+
BignumDtoaMode bignum_mode = DtoaToBignumDtoaMode(mode);
|
| 443 |
+
BignumDtoa(v, bignum_mode, requested_digits, vector, length, point);
|
| 444 |
+
vector[*length] = '\0';
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
} // namespace double_conversion
|
cpp-compiled/sources/double-conversion/double-to-string.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/fast-dtoa.cc
ADDED
|
@@ -0,0 +1,665 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2012 the V8 project authors. All rights reserved.
|
| 2 |
+
// Redistribution and use in source and binary forms, with or without
|
| 3 |
+
// modification, are permitted provided that the following conditions are
|
| 4 |
+
// met:
|
| 5 |
+
//
|
| 6 |
+
// * Redistributions of source code must retain the above copyright
|
| 7 |
+
// notice, this list of conditions and the following disclaimer.
|
| 8 |
+
// * Redistributions in binary form must reproduce the above
|
| 9 |
+
// copyright notice, this list of conditions and the following
|
| 10 |
+
// disclaimer in the documentation and/or other materials provided
|
| 11 |
+
// with the distribution.
|
| 12 |
+
// * Neither the name of Google Inc. nor the names of its
|
| 13 |
+
// contributors may be used to endorse or promote products derived
|
| 14 |
+
// from this software without specific prior written permission.
|
| 15 |
+
//
|
| 16 |
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 17 |
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 18 |
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 19 |
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 20 |
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 21 |
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 22 |
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 23 |
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 24 |
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 25 |
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 26 |
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 |
+
|
| 28 |
+
#include "fast-dtoa.h"
|
| 29 |
+
|
| 30 |
+
#include "cached-powers.h"
|
| 31 |
+
#include "diy-fp.h"
|
| 32 |
+
#include "ieee.h"
|
| 33 |
+
|
| 34 |
+
namespace double_conversion {
|
| 35 |
+
|
| 36 |
+
// The minimal and maximal target exponent define the range of w's binary
|
| 37 |
+
// exponent, where 'w' is the result of multiplying the input by a cached power
|
| 38 |
+
// of ten.
|
| 39 |
+
//
|
| 40 |
+
// A different range might be chosen on a different platform, to optimize digit
|
| 41 |
+
// generation, but a smaller range requires more powers of ten to be cached.
|
| 42 |
+
static const int kMinimalTargetExponent = -60;
|
| 43 |
+
static const int kMaximalTargetExponent = -32;
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
// Adjusts the last digit of the generated number, and screens out generated
|
| 47 |
+
// solutions that may be inaccurate. A solution may be inaccurate if it is
|
| 48 |
+
// outside the safe interval, or if we cannot prove that it is closer to the
|
| 49 |
+
// input than a neighboring representation of the same length.
|
| 50 |
+
//
|
| 51 |
+
// Input: * buffer containing the digits of too_high / 10^kappa
|
| 52 |
+
// * the buffer's length
|
| 53 |
+
// * distance_too_high_w == (too_high - w).f() * unit
|
| 54 |
+
// * unsafe_interval == (too_high - too_low).f() * unit
|
| 55 |
+
// * rest = (too_high - buffer * 10^kappa).f() * unit
|
| 56 |
+
// * ten_kappa = 10^kappa * unit
|
| 57 |
+
// * unit = the common multiplier
|
| 58 |
+
// Output: returns true if the buffer is guaranteed to contain the closest
|
| 59 |
+
// representable number to the input.
|
| 60 |
+
// Modifies the generated digits in the buffer to approach (round towards) w.
|
| 61 |
+
static bool RoundWeed(Vector<char> buffer,
|
| 62 |
+
int length,
|
| 63 |
+
uint64_t distance_too_high_w,
|
| 64 |
+
uint64_t unsafe_interval,
|
| 65 |
+
uint64_t rest,
|
| 66 |
+
uint64_t ten_kappa,
|
| 67 |
+
uint64_t unit) {
|
| 68 |
+
uint64_t small_distance = distance_too_high_w - unit;
|
| 69 |
+
uint64_t big_distance = distance_too_high_w + unit;
|
| 70 |
+
// Let w_low = too_high - big_distance, and
|
| 71 |
+
// w_high = too_high - small_distance.
|
| 72 |
+
// Note: w_low < w < w_high
|
| 73 |
+
//
|
| 74 |
+
// The real w (* unit) must lie somewhere inside the interval
|
| 75 |
+
// ]w_low; w_high[ (often written as "(w_low; w_high)")
|
| 76 |
+
|
| 77 |
+
// Basically the buffer currently contains a number in the unsafe interval
|
| 78 |
+
// ]too_low; too_high[ with too_low < w < too_high
|
| 79 |
+
//
|
| 80 |
+
// too_high - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 81 |
+
// ^v 1 unit ^ ^ ^ ^
|
| 82 |
+
// boundary_high --------------------- . . . .
|
| 83 |
+
// ^v 1 unit . . . .
|
| 84 |
+
// - - - - - - - - - - - - - - - - - - - + - - + - - - - - - . .
|
| 85 |
+
// . . ^ . .
|
| 86 |
+
// . big_distance . . .
|
| 87 |
+
// . . . . rest
|
| 88 |
+
// small_distance . . . .
|
| 89 |
+
// v . . . .
|
| 90 |
+
// w_high - - - - - - - - - - - - - - - - - - . . . .
|
| 91 |
+
// ^v 1 unit . . . .
|
| 92 |
+
// w ---------------------------------------- . . . .
|
| 93 |
+
// ^v 1 unit v . . .
|
| 94 |
+
// w_low - - - - - - - - - - - - - - - - - - - - - . . .
|
| 95 |
+
// . . v
|
| 96 |
+
// buffer --------------------------------------------------+-------+--------
|
| 97 |
+
// . .
|
| 98 |
+
// safe_interval .
|
| 99 |
+
// v .
|
| 100 |
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - .
|
| 101 |
+
// ^v 1 unit .
|
| 102 |
+
// boundary_low ------------------------- unsafe_interval
|
| 103 |
+
// ^v 1 unit v
|
| 104 |
+
// too_low - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
| 105 |
+
//
|
| 106 |
+
//
|
| 107 |
+
// Note that the value of buffer could lie anywhere inside the range too_low
|
| 108 |
+
// to too_high.
|
| 109 |
+
//
|
| 110 |
+
// boundary_low, boundary_high and w are approximations of the real boundaries
|
| 111 |
+
// and v (the input number). They are guaranteed to be precise up to one unit.
|
| 112 |
+
// In fact the error is guaranteed to be strictly less than one unit.
|
| 113 |
+
//
|
| 114 |
+
// Anything that lies outside the unsafe interval is guaranteed not to round
|
| 115 |
+
// to v when read again.
|
| 116 |
+
// Anything that lies inside the safe interval is guaranteed to round to v
|
| 117 |
+
// when read again.
|
| 118 |
+
// If the number inside the buffer lies inside the unsafe interval but not
|
| 119 |
+
// inside the safe interval then we simply do not know and bail out (returning
|
| 120 |
+
// false).
|
| 121 |
+
//
|
| 122 |
+
// Similarly we have to take into account the imprecision of 'w' when finding
|
| 123 |
+
// the closest representation of 'w'. If we have two potential
|
| 124 |
+
// representations, and one is closer to both w_low and w_high, then we know
|
| 125 |
+
// it is closer to the actual value v.
|
| 126 |
+
//
|
| 127 |
+
// By generating the digits of too_high we got the largest (closest to
|
| 128 |
+
// too_high) buffer that is still in the unsafe interval. In the case where
|
| 129 |
+
// w_high < buffer < too_high we try to decrement the buffer.
|
| 130 |
+
// This way the buffer approaches (rounds towards) w.
|
| 131 |
+
// There are 3 conditions that stop the decrementation process:
|
| 132 |
+
// 1) the buffer is already below w_high
|
| 133 |
+
// 2) decrementing the buffer would make it leave the unsafe interval
|
| 134 |
+
// 3) decrementing the buffer would yield a number below w_high and farther
|
| 135 |
+
// away than the current number. In other words:
|
| 136 |
+
// (buffer{-1} < w_high) && w_high - buffer{-1} > buffer - w_high
|
| 137 |
+
// Instead of using the buffer directly we use its distance to too_high.
|
| 138 |
+
// Conceptually rest ~= too_high - buffer
|
| 139 |
+
// We need to do the following tests in this order to avoid over- and
|
| 140 |
+
// underflows.
|
| 141 |
+
DOUBLE_CONVERSION_ASSERT(rest <= unsafe_interval);
|
| 142 |
+
while (rest < small_distance && // Negated condition 1
|
| 143 |
+
unsafe_interval - rest >= ten_kappa && // Negated condition 2
|
| 144 |
+
(rest + ten_kappa < small_distance || // buffer{-1} > w_high
|
| 145 |
+
small_distance - rest >= rest + ten_kappa - small_distance)) {
|
| 146 |
+
buffer[length - 1]--;
|
| 147 |
+
rest += ten_kappa;
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
// We have approached w+ as much as possible. We now test if approaching w-
|
| 151 |
+
// would require changing the buffer. If yes, then we have two possible
|
| 152 |
+
// representations close to w, but we cannot decide which one is closer.
|
| 153 |
+
if (rest < big_distance &&
|
| 154 |
+
unsafe_interval - rest >= ten_kappa &&
|
| 155 |
+
(rest + ten_kappa < big_distance ||
|
| 156 |
+
big_distance - rest > rest + ten_kappa - big_distance)) {
|
| 157 |
+
return false;
|
| 158 |
+
}
|
| 159 |
+
|
| 160 |
+
// Weeding test.
|
| 161 |
+
// The safe interval is [too_low + 2 ulp; too_high - 2 ulp]
|
| 162 |
+
// Since too_low = too_high - unsafe_interval this is equivalent to
|
| 163 |
+
// [too_high - unsafe_interval + 4 ulp; too_high - 2 ulp]
|
| 164 |
+
// Conceptually we have: rest ~= too_high - buffer
|
| 165 |
+
return (2 * unit <= rest) && (rest <= unsafe_interval - 4 * unit);
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
// Rounds the buffer upwards if the result is closer to v by possibly adding
|
| 170 |
+
// 1 to the buffer. If the precision of the calculation is not sufficient to
|
| 171 |
+
// round correctly, return false.
|
| 172 |
+
// The rounding might shift the whole buffer in which case the kappa is
|
| 173 |
+
// adjusted. For example "99", kappa = 3 might become "10", kappa = 4.
|
| 174 |
+
//
|
| 175 |
+
// If 2*rest > ten_kappa then the buffer needs to be round up.
|
| 176 |
+
// rest can have an error of +/- 1 unit. This function accounts for the
|
| 177 |
+
// imprecision and returns false, if the rounding direction cannot be
|
| 178 |
+
// unambiguously determined.
|
| 179 |
+
//
|
| 180 |
+
// Precondition: rest < ten_kappa.
|
| 181 |
+
static bool RoundWeedCounted(Vector<char> buffer,
|
| 182 |
+
int length,
|
| 183 |
+
uint64_t rest,
|
| 184 |
+
uint64_t ten_kappa,
|
| 185 |
+
uint64_t unit,
|
| 186 |
+
int* kappa) {
|
| 187 |
+
DOUBLE_CONVERSION_ASSERT(rest < ten_kappa);
|
| 188 |
+
// The following tests are done in a specific order to avoid overflows. They
|
| 189 |
+
// will work correctly with any uint64 values of rest < ten_kappa and unit.
|
| 190 |
+
//
|
| 191 |
+
// If the unit is too big, then we don't know which way to round. For example
|
| 192 |
+
// a unit of 50 means that the real number lies within rest +/- 50. If
|
| 193 |
+
// 10^kappa == 40 then there is no way to tell which way to round.
|
| 194 |
+
if (unit >= ten_kappa) return false;
|
| 195 |
+
// Even if unit is just half the size of 10^kappa we are already completely
|
| 196 |
+
// lost. (And after the previous test we know that the expression will not
|
| 197 |
+
// over/underflow.)
|
| 198 |
+
if (ten_kappa - unit <= unit) return false;
|
| 199 |
+
// If 2 * (rest + unit) <= 10^kappa we can safely round down.
|
| 200 |
+
if ((ten_kappa - rest > rest) && (ten_kappa - 2 * rest >= 2 * unit)) {
|
| 201 |
+
return true;
|
| 202 |
+
}
|
| 203 |
+
// If 2 * (rest - unit) >= 10^kappa, then we can safely round up.
|
| 204 |
+
if ((rest > unit) && (ten_kappa - (rest - unit) <= (rest - unit))) {
|
| 205 |
+
// Increment the last digit recursively until we find a non '9' digit.
|
| 206 |
+
buffer[length - 1]++;
|
| 207 |
+
for (int i = length - 1; i > 0; --i) {
|
| 208 |
+
if (buffer[i] != '0' + 10) break;
|
| 209 |
+
buffer[i] = '0';
|
| 210 |
+
buffer[i - 1]++;
|
| 211 |
+
}
|
| 212 |
+
// If the first digit is now '0'+ 10 we had a buffer with all '9's. With the
|
| 213 |
+
// exception of the first digit all digits are now '0'. Simply switch the
|
| 214 |
+
// first digit to '1' and adjust the kappa. Example: "99" becomes "10" and
|
| 215 |
+
// the power (the kappa) is increased.
|
| 216 |
+
if (buffer[0] == '0' + 10) {
|
| 217 |
+
buffer[0] = '1';
|
| 218 |
+
(*kappa) += 1;
|
| 219 |
+
}
|
| 220 |
+
return true;
|
| 221 |
+
}
|
| 222 |
+
return false;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
// Returns the biggest power of ten that is less than or equal to the given
|
| 226 |
+
// number. We furthermore receive the maximum number of bits 'number' has.
|
| 227 |
+
//
|
| 228 |
+
// Returns power == 10^(exponent_plus_one-1) such that
|
| 229 |
+
// power <= number < power * 10.
|
| 230 |
+
// If number_bits == 0 then 0^(0-1) is returned.
|
| 231 |
+
// The number of bits must be <= 32.
|
| 232 |
+
// Precondition: number < (1 << (number_bits + 1)).
|
| 233 |
+
|
| 234 |
+
// Inspired by the method for finding an integer log base 10 from here:
|
| 235 |
+
// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLog10
|
| 236 |
+
static unsigned int const kSmallPowersOfTen[] =
|
| 237 |
+
{0, 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000,
|
| 238 |
+
1000000000};
|
| 239 |
+
|
| 240 |
+
static void BiggestPowerTen(uint32_t number,
|
| 241 |
+
int number_bits,
|
| 242 |
+
uint32_t* power,
|
| 243 |
+
int* exponent_plus_one) {
|
| 244 |
+
DOUBLE_CONVERSION_ASSERT(number < (1u << (number_bits + 1)));
|
| 245 |
+
// 1233/4096 is approximately 1/lg(10).
|
| 246 |
+
int exponent_plus_one_guess = ((number_bits + 1) * 1233 >> 12);
|
| 247 |
+
// We increment to skip over the first entry in the kPowersOf10 table.
|
| 248 |
+
// Note: kPowersOf10[i] == 10^(i-1).
|
| 249 |
+
exponent_plus_one_guess++;
|
| 250 |
+
// We don't have any guarantees that 2^number_bits <= number.
|
| 251 |
+
if (number < kSmallPowersOfTen[exponent_plus_one_guess]) {
|
| 252 |
+
exponent_plus_one_guess--;
|
| 253 |
+
}
|
| 254 |
+
*power = kSmallPowersOfTen[exponent_plus_one_guess];
|
| 255 |
+
*exponent_plus_one = exponent_plus_one_guess;
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
// Generates the digits of input number w.
|
| 259 |
+
// w is a floating-point number (DiyFp), consisting of a significand and an
|
| 260 |
+
// exponent. Its exponent is bounded by kMinimalTargetExponent and
|
| 261 |
+
// kMaximalTargetExponent.
|
| 262 |
+
// Hence -60 <= w.e() <= -32.
|
| 263 |
+
//
|
| 264 |
+
// Returns false if it fails, in which case the generated digits in the buffer
|
| 265 |
+
// should not be used.
|
| 266 |
+
// Preconditions:
|
| 267 |
+
// * low, w and high are correct up to 1 ulp (unit in the last place). That
|
| 268 |
+
// is, their error must be less than a unit of their last digits.
|
| 269 |
+
// * low.e() == w.e() == high.e()
|
| 270 |
+
// * low < w < high, and taking into account their error: low~ <= high~
|
| 271 |
+
// * kMinimalTargetExponent <= w.e() <= kMaximalTargetExponent
|
| 272 |
+
// Postconditions: returns false if procedure fails.
|
| 273 |
+
// otherwise:
|
| 274 |
+
// * buffer is not null-terminated, but len contains the number of digits.
|
| 275 |
+
// * buffer contains the shortest possible decimal digit-sequence
|
| 276 |
+
// such that LOW < buffer * 10^kappa < HIGH, where LOW and HIGH are the
|
| 277 |
+
// correct values of low and high (without their error).
|
| 278 |
+
// * if more than one decimal representation gives the minimal number of
|
| 279 |
+
// decimal digits then the one closest to W (where W is the correct value
|
| 280 |
+
// of w) is chosen.
|
| 281 |
+
// Remark: this procedure takes into account the imprecision of its input
|
| 282 |
+
// numbers. If the precision is not enough to guarantee all the postconditions
|
| 283 |
+
// then false is returned. This usually happens rarely (~0.5%).
|
| 284 |
+
//
|
| 285 |
+
// Say, for the sake of example, that
|
| 286 |
+
// w.e() == -48, and w.f() == 0x1234567890abcdef
|
| 287 |
+
// w's value can be computed by w.f() * 2^w.e()
|
| 288 |
+
// We can obtain w's integral digits by simply shifting w.f() by -w.e().
|
| 289 |
+
// -> w's integral part is 0x1234
|
| 290 |
+
// w's fractional part is therefore 0x567890abcdef.
|
| 291 |
+
// Printing w's integral part is easy (simply print 0x1234 in decimal).
|
| 292 |
+
// In order to print its fraction we repeatedly multiply the fraction by 10 and
|
| 293 |
+
// get each digit. Example the first digit after the point would be computed by
|
| 294 |
+
// (0x567890abcdef * 10) >> 48. -> 3
|
| 295 |
+
// The whole thing becomes slightly more complicated because we want to stop
|
| 296 |
+
// once we have enough digits. That is, once the digits inside the buffer
|
| 297 |
+
// represent 'w' we can stop. Everything inside the interval low - high
|
| 298 |
+
// represents w. However we have to pay attention to low, high and w's
|
| 299 |
+
// imprecision.
|
| 300 |
+
static bool DigitGen(DiyFp low,
|
| 301 |
+
DiyFp w,
|
| 302 |
+
DiyFp high,
|
| 303 |
+
Vector<char> buffer,
|
| 304 |
+
int* length,
|
| 305 |
+
int* kappa) {
|
| 306 |
+
DOUBLE_CONVERSION_ASSERT(low.e() == w.e() && w.e() == high.e());
|
| 307 |
+
DOUBLE_CONVERSION_ASSERT(low.f() + 1 <= high.f() - 1);
|
| 308 |
+
DOUBLE_CONVERSION_ASSERT(kMinimalTargetExponent <= w.e() && w.e() <= kMaximalTargetExponent);
|
| 309 |
+
// low, w and high are imprecise, but by less than one ulp (unit in the last
|
| 310 |
+
// place).
|
| 311 |
+
// If we remove (resp. add) 1 ulp from low (resp. high) we are certain that
|
| 312 |
+
// the new numbers are outside of the interval we want the final
|
| 313 |
+
// representation to lie in.
|
| 314 |
+
// Inversely adding (resp. removing) 1 ulp from low (resp. high) would yield
|
| 315 |
+
// numbers that are certain to lie in the interval. We will use this fact
|
| 316 |
+
// later on.
|
| 317 |
+
// We will now start by generating the digits within the uncertain
|
| 318 |
+
// interval. Later we will weed out representations that lie outside the safe
|
| 319 |
+
// interval and thus _might_ lie outside the correct interval.
|
| 320 |
+
uint64_t unit = 1;
|
| 321 |
+
DiyFp too_low = DiyFp(low.f() - unit, low.e());
|
| 322 |
+
DiyFp too_high = DiyFp(high.f() + unit, high.e());
|
| 323 |
+
// too_low and too_high are guaranteed to lie outside the interval we want the
|
| 324 |
+
// generated number in.
|
| 325 |
+
DiyFp unsafe_interval = DiyFp::Minus(too_high, too_low);
|
| 326 |
+
// We now cut the input number into two parts: the integral digits and the
|
| 327 |
+
// fractionals. We will not write any decimal separator though, but adapt
|
| 328 |
+
// kappa instead.
|
| 329 |
+
// Reminder: we are currently computing the digits (stored inside the buffer)
|
| 330 |
+
// such that: too_low < buffer * 10^kappa < too_high
|
| 331 |
+
// We use too_high for the digit_generation and stop as soon as possible.
|
| 332 |
+
// If we stop early we effectively round down.
|
| 333 |
+
DiyFp one = DiyFp(static_cast<uint64_t>(1) << -w.e(), w.e());
|
| 334 |
+
// Division by one is a shift.
|
| 335 |
+
uint32_t integrals = static_cast<uint32_t>(too_high.f() >> -one.e());
|
| 336 |
+
// Modulo by one is an and.
|
| 337 |
+
uint64_t fractionals = too_high.f() & (one.f() - 1);
|
| 338 |
+
uint32_t divisor;
|
| 339 |
+
int divisor_exponent_plus_one;
|
| 340 |
+
BiggestPowerTen(integrals, DiyFp::kSignificandSize - (-one.e()),
|
| 341 |
+
&divisor, &divisor_exponent_plus_one);
|
| 342 |
+
*kappa = divisor_exponent_plus_one;
|
| 343 |
+
*length = 0;
|
| 344 |
+
// Loop invariant: buffer = too_high / 10^kappa (integer division)
|
| 345 |
+
// The invariant holds for the first iteration: kappa has been initialized
|
| 346 |
+
// with the divisor exponent + 1. And the divisor is the biggest power of ten
|
| 347 |
+
// that is smaller than integrals.
|
| 348 |
+
while (*kappa > 0) {
|
| 349 |
+
int digit = integrals / divisor;
|
| 350 |
+
DOUBLE_CONVERSION_ASSERT(digit <= 9);
|
| 351 |
+
buffer[*length] = static_cast<char>('0' + digit);
|
| 352 |
+
(*length)++;
|
| 353 |
+
integrals %= divisor;
|
| 354 |
+
(*kappa)--;
|
| 355 |
+
// Note that kappa now equals the exponent of the divisor and that the
|
| 356 |
+
// invariant thus holds again.
|
| 357 |
+
uint64_t rest =
|
| 358 |
+
(static_cast<uint64_t>(integrals) << -one.e()) + fractionals;
|
| 359 |
+
// Invariant: too_high = buffer * 10^kappa + DiyFp(rest, one.e())
|
| 360 |
+
// Reminder: unsafe_interval.e() == one.e()
|
| 361 |
+
if (rest < unsafe_interval.f()) {
|
| 362 |
+
// Rounding down (by not emitting the remaining digits) yields a number
|
| 363 |
+
// that lies within the unsafe interval.
|
| 364 |
+
return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f(),
|
| 365 |
+
unsafe_interval.f(), rest,
|
| 366 |
+
static_cast<uint64_t>(divisor) << -one.e(), unit);
|
| 367 |
+
}
|
| 368 |
+
divisor /= 10;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
// The integrals have been generated. We are at the point of the decimal
|
| 372 |
+
// separator. In the following loop we simply multiply the remaining digits by
|
| 373 |
+
// 10 and divide by one. We just need to pay attention to multiply associated
|
| 374 |
+
// data (like the interval or 'unit'), too.
|
| 375 |
+
// Note that the multiplication by 10 does not overflow, because w.e >= -60
|
| 376 |
+
// and thus one.e >= -60.
|
| 377 |
+
DOUBLE_CONVERSION_ASSERT(one.e() >= -60);
|
| 378 |
+
DOUBLE_CONVERSION_ASSERT(fractionals < one.f());
|
| 379 |
+
DOUBLE_CONVERSION_ASSERT(DOUBLE_CONVERSION_UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF) / 10 >= one.f());
|
| 380 |
+
for (;;) {
|
| 381 |
+
fractionals *= 10;
|
| 382 |
+
unit *= 10;
|
| 383 |
+
unsafe_interval.set_f(unsafe_interval.f() * 10);
|
| 384 |
+
// Integer division by one.
|
| 385 |
+
int digit = static_cast<int>(fractionals >> -one.e());
|
| 386 |
+
DOUBLE_CONVERSION_ASSERT(digit <= 9);
|
| 387 |
+
buffer[*length] = static_cast<char>('0' + digit);
|
| 388 |
+
(*length)++;
|
| 389 |
+
fractionals &= one.f() - 1; // Modulo by one.
|
| 390 |
+
(*kappa)--;
|
| 391 |
+
if (fractionals < unsafe_interval.f()) {
|
| 392 |
+
return RoundWeed(buffer, *length, DiyFp::Minus(too_high, w).f() * unit,
|
| 393 |
+
unsafe_interval.f(), fractionals, one.f(), unit);
|
| 394 |
+
}
|
| 395 |
+
}
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
// Generates (at most) requested_digits digits of input number w.
|
| 401 |
+
// w is a floating-point number (DiyFp), consisting of a significand and an
|
| 402 |
+
// exponent. Its exponent is bounded by kMinimalTargetExponent and
|
| 403 |
+
// kMaximalTargetExponent.
|
| 404 |
+
// Hence -60 <= w.e() <= -32.
|
| 405 |
+
//
|
| 406 |
+
// Returns false if it fails, in which case the generated digits in the buffer
|
| 407 |
+
// should not be used.
|
| 408 |
+
// Preconditions:
|
| 409 |
+
// * w is correct up to 1 ulp (unit in the last place). That
|
| 410 |
+
// is, its error must be strictly less than a unit of its last digit.
|
| 411 |
+
// * kMinimalTargetExponent <= w.e() <= kMaximalTargetExponent
|
| 412 |
+
//
|
| 413 |
+
// Postconditions: returns false if procedure fails.
|
| 414 |
+
// otherwise:
|
| 415 |
+
// * buffer is not null-terminated, but length contains the number of
|
| 416 |
+
// digits.
|
| 417 |
+
// * the representation in buffer is the most precise representation of
|
| 418 |
+
// requested_digits digits.
|
| 419 |
+
// * buffer contains at most requested_digits digits of w. If there are less
|
| 420 |
+
// than requested_digits digits then some trailing '0's have been removed.
|
| 421 |
+
// * kappa is such that
|
| 422 |
+
// w = buffer * 10^kappa + eps with |eps| < 10^kappa / 2.
|
| 423 |
+
//
|
| 424 |
+
// Remark: This procedure takes into account the imprecision of its input
|
| 425 |
+
// numbers. If the precision is not enough to guarantee all the postconditions
|
| 426 |
+
// then false is returned. This usually happens rarely, but the failure-rate
|
| 427 |
+
// increases with higher requested_digits.
|
| 428 |
+
static bool DigitGenCounted(DiyFp w,
|
| 429 |
+
int requested_digits,
|
| 430 |
+
Vector<char> buffer,
|
| 431 |
+
int* length,
|
| 432 |
+
int* kappa) {
|
| 433 |
+
DOUBLE_CONVERSION_ASSERT(kMinimalTargetExponent <= w.e() && w.e() <= kMaximalTargetExponent);
|
| 434 |
+
DOUBLE_CONVERSION_ASSERT(kMinimalTargetExponent >= -60);
|
| 435 |
+
DOUBLE_CONVERSION_ASSERT(kMaximalTargetExponent <= -32);
|
| 436 |
+
// w is assumed to have an error less than 1 unit. Whenever w is scaled we
|
| 437 |
+
// also scale its error.
|
| 438 |
+
uint64_t w_error = 1;
|
| 439 |
+
// We cut the input number into two parts: the integral digits and the
|
| 440 |
+
// fractional digits. We don't emit any decimal separator, but adapt kappa
|
| 441 |
+
// instead. Example: instead of writing "1.2" we put "12" into the buffer and
|
| 442 |
+
// increase kappa by 1.
|
| 443 |
+
DiyFp one = DiyFp(static_cast<uint64_t>(1) << -w.e(), w.e());
|
| 444 |
+
// Division by one is a shift.
|
| 445 |
+
uint32_t integrals = static_cast<uint32_t>(w.f() >> -one.e());
|
| 446 |
+
// Modulo by one is an and.
|
| 447 |
+
uint64_t fractionals = w.f() & (one.f() - 1);
|
| 448 |
+
uint32_t divisor;
|
| 449 |
+
int divisor_exponent_plus_one;
|
| 450 |
+
BiggestPowerTen(integrals, DiyFp::kSignificandSize - (-one.e()),
|
| 451 |
+
&divisor, &divisor_exponent_plus_one);
|
| 452 |
+
*kappa = divisor_exponent_plus_one;
|
| 453 |
+
*length = 0;
|
| 454 |
+
|
| 455 |
+
// Loop invariant: buffer = w / 10^kappa (integer division)
|
| 456 |
+
// The invariant holds for the first iteration: kappa has been initialized
|
| 457 |
+
// with the divisor exponent + 1. And the divisor is the biggest power of ten
|
| 458 |
+
// that is smaller than 'integrals'.
|
| 459 |
+
while (*kappa > 0) {
|
| 460 |
+
int digit = integrals / divisor;
|
| 461 |
+
DOUBLE_CONVERSION_ASSERT(digit <= 9);
|
| 462 |
+
buffer[*length] = static_cast<char>('0' + digit);
|
| 463 |
+
(*length)++;
|
| 464 |
+
requested_digits--;
|
| 465 |
+
integrals %= divisor;
|
| 466 |
+
(*kappa)--;
|
| 467 |
+
// Note that kappa now equals the exponent of the divisor and that the
|
| 468 |
+
// invariant thus holds again.
|
| 469 |
+
if (requested_digits == 0) break;
|
| 470 |
+
divisor /= 10;
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
if (requested_digits == 0) {
|
| 474 |
+
uint64_t rest =
|
| 475 |
+
(static_cast<uint64_t>(integrals) << -one.e()) + fractionals;
|
| 476 |
+
return RoundWeedCounted(buffer, *length, rest,
|
| 477 |
+
static_cast<uint64_t>(divisor) << -one.e(), w_error,
|
| 478 |
+
kappa);
|
| 479 |
+
}
|
| 480 |
+
|
| 481 |
+
// The integrals have been generated. We are at the point of the decimal
|
| 482 |
+
// separator. In the following loop we simply multiply the remaining digits by
|
| 483 |
+
// 10 and divide by one. We just need to pay attention to multiply associated
|
| 484 |
+
// data (the 'unit'), too.
|
| 485 |
+
// Note that the multiplication by 10 does not overflow, because w.e >= -60
|
| 486 |
+
// and thus one.e >= -60.
|
| 487 |
+
DOUBLE_CONVERSION_ASSERT(one.e() >= -60);
|
| 488 |
+
DOUBLE_CONVERSION_ASSERT(fractionals < one.f());
|
| 489 |
+
DOUBLE_CONVERSION_ASSERT(DOUBLE_CONVERSION_UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF) / 10 >= one.f());
|
| 490 |
+
while (requested_digits > 0 && fractionals > w_error) {
|
| 491 |
+
fractionals *= 10;
|
| 492 |
+
w_error *= 10;
|
| 493 |
+
// Integer division by one.
|
| 494 |
+
int digit = static_cast<int>(fractionals >> -one.e());
|
| 495 |
+
DOUBLE_CONVERSION_ASSERT(digit <= 9);
|
| 496 |
+
buffer[*length] = static_cast<char>('0' + digit);
|
| 497 |
+
(*length)++;
|
| 498 |
+
requested_digits--;
|
| 499 |
+
fractionals &= one.f() - 1; // Modulo by one.
|
| 500 |
+
(*kappa)--;
|
| 501 |
+
}
|
| 502 |
+
if (requested_digits != 0) return false;
|
| 503 |
+
return RoundWeedCounted(buffer, *length, fractionals, one.f(), w_error,
|
| 504 |
+
kappa);
|
| 505 |
+
}
|
| 506 |
+
|
| 507 |
+
|
| 508 |
+
// Provides a decimal representation of v.
|
| 509 |
+
// Returns true if it succeeds, otherwise the result cannot be trusted.
|
| 510 |
+
// There will be *length digits inside the buffer (not null-terminated).
|
| 511 |
+
// If the function returns true then
|
| 512 |
+
// v == (double) (buffer * 10^decimal_exponent).
|
| 513 |
+
// The digits in the buffer are the shortest representation possible: no
|
| 514 |
+
// 0.09999999999999999 instead of 0.1. The shorter representation will even be
|
| 515 |
+
// chosen even if the longer one would be closer to v.
|
| 516 |
+
// The last digit will be closest to the actual v. That is, even if several
|
| 517 |
+
// digits might correctly yield 'v' when read again, the closest will be
|
| 518 |
+
// computed.
|
| 519 |
+
static bool Grisu3(double v,
|
| 520 |
+
FastDtoaMode mode,
|
| 521 |
+
Vector<char> buffer,
|
| 522 |
+
int* length,
|
| 523 |
+
int* decimal_exponent) {
|
| 524 |
+
DiyFp w = Double(v).AsNormalizedDiyFp();
|
| 525 |
+
// boundary_minus and boundary_plus are the boundaries between v and its
|
| 526 |
+
// closest floating-point neighbors. Any number strictly between
|
| 527 |
+
// boundary_minus and boundary_plus will round to v when convert to a double.
|
| 528 |
+
// Grisu3 will never output representations that lie exactly on a boundary.
|
| 529 |
+
DiyFp boundary_minus, boundary_plus;
|
| 530 |
+
if (mode == FAST_DTOA_SHORTEST) {
|
| 531 |
+
Double(v).NormalizedBoundaries(&boundary_minus, &boundary_plus);
|
| 532 |
+
} else {
|
| 533 |
+
DOUBLE_CONVERSION_ASSERT(mode == FAST_DTOA_SHORTEST_SINGLE);
|
| 534 |
+
float single_v = static_cast<float>(v);
|
| 535 |
+
Single(single_v).NormalizedBoundaries(&boundary_minus, &boundary_plus);
|
| 536 |
+
}
|
| 537 |
+
DOUBLE_CONVERSION_ASSERT(boundary_plus.e() == w.e());
|
| 538 |
+
DiyFp ten_mk; // Cached power of ten: 10^-k
|
| 539 |
+
int mk; // -k
|
| 540 |
+
int ten_mk_minimal_binary_exponent =
|
| 541 |
+
kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize);
|
| 542 |
+
int ten_mk_maximal_binary_exponent =
|
| 543 |
+
kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize);
|
| 544 |
+
PowersOfTenCache::GetCachedPowerForBinaryExponentRange(
|
| 545 |
+
ten_mk_minimal_binary_exponent,
|
| 546 |
+
ten_mk_maximal_binary_exponent,
|
| 547 |
+
&ten_mk, &mk);
|
| 548 |
+
DOUBLE_CONVERSION_ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() +
|
| 549 |
+
DiyFp::kSignificandSize) &&
|
| 550 |
+
(kMaximalTargetExponent >= w.e() + ten_mk.e() +
|
| 551 |
+
DiyFp::kSignificandSize));
|
| 552 |
+
// Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a
|
| 553 |
+
// 64 bit significand and ten_mk is thus only precise up to 64 bits.
|
| 554 |
+
|
| 555 |
+
// The DiyFp::Times procedure rounds its result, and ten_mk is approximated
|
| 556 |
+
// too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now
|
| 557 |
+
// off by a small amount.
|
| 558 |
+
// In fact: scaled_w - w*10^k < 1ulp (unit in the last place) of scaled_w.
|
| 559 |
+
// In other words: let f = scaled_w.f() and e = scaled_w.e(), then
|
| 560 |
+
// (f-1) * 2^e < w*10^k < (f+1) * 2^e
|
| 561 |
+
DiyFp scaled_w = DiyFp::Times(w, ten_mk);
|
| 562 |
+
DOUBLE_CONVERSION_ASSERT(scaled_w.e() ==
|
| 563 |
+
boundary_plus.e() + ten_mk.e() + DiyFp::kSignificandSize);
|
| 564 |
+
// In theory it would be possible to avoid some recomputations by computing
|
| 565 |
+
// the difference between w and boundary_minus/plus (a power of 2) and to
|
| 566 |
+
// compute scaled_boundary_minus/plus by subtracting/adding from
|
| 567 |
+
// scaled_w. However the code becomes much less readable and the speed
|
| 568 |
+
// enhancements are not terrific.
|
| 569 |
+
DiyFp scaled_boundary_minus = DiyFp::Times(boundary_minus, ten_mk);
|
| 570 |
+
DiyFp scaled_boundary_plus = DiyFp::Times(boundary_plus, ten_mk);
|
| 571 |
+
|
| 572 |
+
// DigitGen will generate the digits of scaled_w. Therefore we have
|
| 573 |
+
// v == (double) (scaled_w * 10^-mk).
|
| 574 |
+
// Set decimal_exponent == -mk and pass it to DigitGen. If scaled_w is not an
|
| 575 |
+
// integer than it will be updated. For instance if scaled_w == 1.23 then
|
| 576 |
+
// the buffer will be filled with "123" and the decimal_exponent will be
|
| 577 |
+
// decreased by 2.
|
| 578 |
+
int kappa;
|
| 579 |
+
bool result = DigitGen(scaled_boundary_minus, scaled_w, scaled_boundary_plus,
|
| 580 |
+
buffer, length, &kappa);
|
| 581 |
+
*decimal_exponent = -mk + kappa;
|
| 582 |
+
return result;
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
// The "counted" version of grisu3 (see above) only generates requested_digits
|
| 587 |
+
// number of digits. This version does not generate the shortest representation,
|
| 588 |
+
// and with enough requested digits 0.1 will at some point print as 0.9999999...
|
| 589 |
+
// Grisu3 is too imprecise for real halfway cases (1.5 will not work) and
|
| 590 |
+
// therefore the rounding strategy for halfway cases is irrelevant.
|
| 591 |
+
static bool Grisu3Counted(double v,
|
| 592 |
+
int requested_digits,
|
| 593 |
+
Vector<char> buffer,
|
| 594 |
+
int* length,
|
| 595 |
+
int* decimal_exponent) {
|
| 596 |
+
DiyFp w = Double(v).AsNormalizedDiyFp();
|
| 597 |
+
DiyFp ten_mk; // Cached power of ten: 10^-k
|
| 598 |
+
int mk; // -k
|
| 599 |
+
int ten_mk_minimal_binary_exponent =
|
| 600 |
+
kMinimalTargetExponent - (w.e() + DiyFp::kSignificandSize);
|
| 601 |
+
int ten_mk_maximal_binary_exponent =
|
| 602 |
+
kMaximalTargetExponent - (w.e() + DiyFp::kSignificandSize);
|
| 603 |
+
PowersOfTenCache::GetCachedPowerForBinaryExponentRange(
|
| 604 |
+
ten_mk_minimal_binary_exponent,
|
| 605 |
+
ten_mk_maximal_binary_exponent,
|
| 606 |
+
&ten_mk, &mk);
|
| 607 |
+
DOUBLE_CONVERSION_ASSERT((kMinimalTargetExponent <= w.e() + ten_mk.e() +
|
| 608 |
+
DiyFp::kSignificandSize) &&
|
| 609 |
+
(kMaximalTargetExponent >= w.e() + ten_mk.e() +
|
| 610 |
+
DiyFp::kSignificandSize));
|
| 611 |
+
// Note that ten_mk is only an approximation of 10^-k. A DiyFp only contains a
|
| 612 |
+
// 64 bit significand and ten_mk is thus only precise up to 64 bits.
|
| 613 |
+
|
| 614 |
+
// The DiyFp::Times procedure rounds its result, and ten_mk is approximated
|
| 615 |
+
// too. The variable scaled_w (as well as scaled_boundary_minus/plus) are now
|
| 616 |
+
// off by a small amount.
|
| 617 |
+
// In fact: scaled_w - w*10^k < 1ulp (unit in the last place) of scaled_w.
|
| 618 |
+
// In other words: let f = scaled_w.f() and e = scaled_w.e(), then
|
| 619 |
+
// (f-1) * 2^e < w*10^k < (f+1) * 2^e
|
| 620 |
+
DiyFp scaled_w = DiyFp::Times(w, ten_mk);
|
| 621 |
+
|
| 622 |
+
// We now have (double) (scaled_w * 10^-mk).
|
| 623 |
+
// DigitGen will generate the first requested_digits digits of scaled_w and
|
| 624 |
+
// return together with a kappa such that scaled_w ~= buffer * 10^kappa. (It
|
| 625 |
+
// will not always be exactly the same since DigitGenCounted only produces a
|
| 626 |
+
// limited number of digits.)
|
| 627 |
+
int kappa;
|
| 628 |
+
bool result = DigitGenCounted(scaled_w, requested_digits,
|
| 629 |
+
buffer, length, &kappa);
|
| 630 |
+
*decimal_exponent = -mk + kappa;
|
| 631 |
+
return result;
|
| 632 |
+
}
|
| 633 |
+
|
| 634 |
+
|
| 635 |
+
bool FastDtoa(double v,
|
| 636 |
+
FastDtoaMode mode,
|
| 637 |
+
int requested_digits,
|
| 638 |
+
Vector<char> buffer,
|
| 639 |
+
int* length,
|
| 640 |
+
int* decimal_point) {
|
| 641 |
+
DOUBLE_CONVERSION_ASSERT(v > 0);
|
| 642 |
+
DOUBLE_CONVERSION_ASSERT(!Double(v).IsSpecial());
|
| 643 |
+
|
| 644 |
+
bool result = false;
|
| 645 |
+
int decimal_exponent = 0;
|
| 646 |
+
switch (mode) {
|
| 647 |
+
case FAST_DTOA_SHORTEST:
|
| 648 |
+
case FAST_DTOA_SHORTEST_SINGLE:
|
| 649 |
+
result = Grisu3(v, mode, buffer, length, &decimal_exponent);
|
| 650 |
+
break;
|
| 651 |
+
case FAST_DTOA_PRECISION:
|
| 652 |
+
result = Grisu3Counted(v, requested_digits,
|
| 653 |
+
buffer, length, &decimal_exponent);
|
| 654 |
+
break;
|
| 655 |
+
default:
|
| 656 |
+
DOUBLE_CONVERSION_UNREACHABLE();
|
| 657 |
+
}
|
| 658 |
+
if (result) {
|
| 659 |
+
*decimal_point = *length + decimal_exponent;
|
| 660 |
+
buffer[*length] = '\0';
|
| 661 |
+
}
|
| 662 |
+
return result;
|
| 663 |
+
}
|
| 664 |
+
|
| 665 |
+
} // namespace double_conversion
|
cpp-compiled/sources/double-conversion/fast-dtoa.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/fixed-dtoa.cc
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2010 the V8 project authors. All rights reserved.
|
| 2 |
+
// Redistribution and use in source and binary forms, with or without
|
| 3 |
+
// modification, are permitted provided that the following conditions are
|
| 4 |
+
// met:
|
| 5 |
+
//
|
| 6 |
+
// * Redistributions of source code must retain the above copyright
|
| 7 |
+
// notice, this list of conditions and the following disclaimer.
|
| 8 |
+
// * Redistributions in binary form must reproduce the above
|
| 9 |
+
// copyright notice, this list of conditions and the following
|
| 10 |
+
// disclaimer in the documentation and/or other materials provided
|
| 11 |
+
// with the distribution.
|
| 12 |
+
// * Neither the name of Google Inc. nor the names of its
|
| 13 |
+
// contributors may be used to endorse or promote products derived
|
| 14 |
+
// from this software without specific prior written permission.
|
| 15 |
+
//
|
| 16 |
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 17 |
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 18 |
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 19 |
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 20 |
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 21 |
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 22 |
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 23 |
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 24 |
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 25 |
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 26 |
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 |
+
|
| 28 |
+
#include <cmath>
|
| 29 |
+
|
| 30 |
+
#include "fixed-dtoa.h"
|
| 31 |
+
#include "ieee.h"
|
| 32 |
+
|
| 33 |
+
namespace double_conversion {
|
| 34 |
+
|
| 35 |
+
// Represents a 128bit type. This class should be replaced by a native type on
|
| 36 |
+
// platforms that support 128bit integers.
|
| 37 |
+
class UInt128 {
|
| 38 |
+
public:
|
| 39 |
+
UInt128() : high_bits_(0), low_bits_(0) { }
|
| 40 |
+
UInt128(uint64_t high, uint64_t low) : high_bits_(high), low_bits_(low) { }
|
| 41 |
+
|
| 42 |
+
void Multiply(uint32_t multiplicand) {
|
| 43 |
+
uint64_t accumulator;
|
| 44 |
+
|
| 45 |
+
accumulator = (low_bits_ & kMask32) * multiplicand;
|
| 46 |
+
uint32_t part = static_cast<uint32_t>(accumulator & kMask32);
|
| 47 |
+
accumulator >>= 32;
|
| 48 |
+
accumulator = accumulator + (low_bits_ >> 32) * multiplicand;
|
| 49 |
+
low_bits_ = (accumulator << 32) + part;
|
| 50 |
+
accumulator >>= 32;
|
| 51 |
+
accumulator = accumulator + (high_bits_ & kMask32) * multiplicand;
|
| 52 |
+
part = static_cast<uint32_t>(accumulator & kMask32);
|
| 53 |
+
accumulator >>= 32;
|
| 54 |
+
accumulator = accumulator + (high_bits_ >> 32) * multiplicand;
|
| 55 |
+
high_bits_ = (accumulator << 32) + part;
|
| 56 |
+
DOUBLE_CONVERSION_ASSERT((accumulator >> 32) == 0);
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
void Shift(int shift_amount) {
|
| 60 |
+
DOUBLE_CONVERSION_ASSERT(-64 <= shift_amount && shift_amount <= 64);
|
| 61 |
+
if (shift_amount == 0) {
|
| 62 |
+
return;
|
| 63 |
+
} else if (shift_amount == -64) {
|
| 64 |
+
high_bits_ = low_bits_;
|
| 65 |
+
low_bits_ = 0;
|
| 66 |
+
} else if (shift_amount == 64) {
|
| 67 |
+
low_bits_ = high_bits_;
|
| 68 |
+
high_bits_ = 0;
|
| 69 |
+
} else if (shift_amount <= 0) {
|
| 70 |
+
high_bits_ <<= -shift_amount;
|
| 71 |
+
high_bits_ += low_bits_ >> (64 + shift_amount);
|
| 72 |
+
low_bits_ <<= -shift_amount;
|
| 73 |
+
} else {
|
| 74 |
+
low_bits_ >>= shift_amount;
|
| 75 |
+
low_bits_ += high_bits_ << (64 - shift_amount);
|
| 76 |
+
high_bits_ >>= shift_amount;
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
// Modifies *this to *this MOD (2^power).
|
| 81 |
+
// Returns *this DIV (2^power).
|
| 82 |
+
int DivModPowerOf2(int power) {
|
| 83 |
+
if (power >= 64) {
|
| 84 |
+
int result = static_cast<int>(high_bits_ >> (power - 64));
|
| 85 |
+
high_bits_ -= static_cast<uint64_t>(result) << (power - 64);
|
| 86 |
+
return result;
|
| 87 |
+
} else {
|
| 88 |
+
uint64_t part_low = low_bits_ >> power;
|
| 89 |
+
uint64_t part_high = high_bits_ << (64 - power);
|
| 90 |
+
int result = static_cast<int>(part_low + part_high);
|
| 91 |
+
high_bits_ = 0;
|
| 92 |
+
low_bits_ -= part_low << power;
|
| 93 |
+
return result;
|
| 94 |
+
}
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
bool IsZero() const {
|
| 98 |
+
return high_bits_ == 0 && low_bits_ == 0;
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
int BitAt(int position) const {
|
| 102 |
+
if (position >= 64) {
|
| 103 |
+
return static_cast<int>(high_bits_ >> (position - 64)) & 1;
|
| 104 |
+
} else {
|
| 105 |
+
return static_cast<int>(low_bits_ >> position) & 1;
|
| 106 |
+
}
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
private:
|
| 110 |
+
static const uint64_t kMask32 = 0xFFFFFFFF;
|
| 111 |
+
// Value == (high_bits_ << 64) + low_bits_
|
| 112 |
+
uint64_t high_bits_;
|
| 113 |
+
uint64_t low_bits_;
|
| 114 |
+
};
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
static const int kDoubleSignificandSize = 53; // Includes the hidden bit.
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
static void FillDigits32FixedLength(uint32_t number, int requested_length,
|
| 121 |
+
Vector<char> buffer, int* length) {
|
| 122 |
+
for (int i = requested_length - 1; i >= 0; --i) {
|
| 123 |
+
buffer[(*length) + i] = '0' + number % 10;
|
| 124 |
+
number /= 10;
|
| 125 |
+
}
|
| 126 |
+
*length += requested_length;
|
| 127 |
+
}
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
static void FillDigits32(uint32_t number, Vector<char> buffer, int* length) {
|
| 131 |
+
int number_length = 0;
|
| 132 |
+
// We fill the digits in reverse order and exchange them afterwards.
|
| 133 |
+
while (number != 0) {
|
| 134 |
+
int digit = number % 10;
|
| 135 |
+
number /= 10;
|
| 136 |
+
buffer[(*length) + number_length] = static_cast<char>('0' + digit);
|
| 137 |
+
number_length++;
|
| 138 |
+
}
|
| 139 |
+
// Exchange the digits.
|
| 140 |
+
int i = *length;
|
| 141 |
+
int j = *length + number_length - 1;
|
| 142 |
+
while (i < j) {
|
| 143 |
+
char tmp = buffer[i];
|
| 144 |
+
buffer[i] = buffer[j];
|
| 145 |
+
buffer[j] = tmp;
|
| 146 |
+
i++;
|
| 147 |
+
j--;
|
| 148 |
+
}
|
| 149 |
+
*length += number_length;
|
| 150 |
+
}
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
static void FillDigits64FixedLength(uint64_t number,
|
| 154 |
+
Vector<char> buffer, int* length) {
|
| 155 |
+
const uint32_t kTen7 = 10000000;
|
| 156 |
+
// For efficiency cut the number into 3 uint32_t parts, and print those.
|
| 157 |
+
uint32_t part2 = static_cast<uint32_t>(number % kTen7);
|
| 158 |
+
number /= kTen7;
|
| 159 |
+
uint32_t part1 = static_cast<uint32_t>(number % kTen7);
|
| 160 |
+
uint32_t part0 = static_cast<uint32_t>(number / kTen7);
|
| 161 |
+
|
| 162 |
+
FillDigits32FixedLength(part0, 3, buffer, length);
|
| 163 |
+
FillDigits32FixedLength(part1, 7, buffer, length);
|
| 164 |
+
FillDigits32FixedLength(part2, 7, buffer, length);
|
| 165 |
+
}
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
static void FillDigits64(uint64_t number, Vector<char> buffer, int* length) {
|
| 169 |
+
const uint32_t kTen7 = 10000000;
|
| 170 |
+
// For efficiency cut the number into 3 uint32_t parts, and print those.
|
| 171 |
+
uint32_t part2 = static_cast<uint32_t>(number % kTen7);
|
| 172 |
+
number /= kTen7;
|
| 173 |
+
uint32_t part1 = static_cast<uint32_t>(number % kTen7);
|
| 174 |
+
uint32_t part0 = static_cast<uint32_t>(number / kTen7);
|
| 175 |
+
|
| 176 |
+
if (part0 != 0) {
|
| 177 |
+
FillDigits32(part0, buffer, length);
|
| 178 |
+
FillDigits32FixedLength(part1, 7, buffer, length);
|
| 179 |
+
FillDigits32FixedLength(part2, 7, buffer, length);
|
| 180 |
+
} else if (part1 != 0) {
|
| 181 |
+
FillDigits32(part1, buffer, length);
|
| 182 |
+
FillDigits32FixedLength(part2, 7, buffer, length);
|
| 183 |
+
} else {
|
| 184 |
+
FillDigits32(part2, buffer, length);
|
| 185 |
+
}
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
static void RoundUp(Vector<char> buffer, int* length, int* decimal_point) {
|
| 190 |
+
// An empty buffer represents 0.
|
| 191 |
+
if (*length == 0) {
|
| 192 |
+
buffer[0] = '1';
|
| 193 |
+
*decimal_point = 1;
|
| 194 |
+
*length = 1;
|
| 195 |
+
return;
|
| 196 |
+
}
|
| 197 |
+
// Round the last digit until we either have a digit that was not '9' or until
|
| 198 |
+
// we reached the first digit.
|
| 199 |
+
buffer[(*length) - 1]++;
|
| 200 |
+
for (int i = (*length) - 1; i > 0; --i) {
|
| 201 |
+
if (buffer[i] != '0' + 10) {
|
| 202 |
+
return;
|
| 203 |
+
}
|
| 204 |
+
buffer[i] = '0';
|
| 205 |
+
buffer[i - 1]++;
|
| 206 |
+
}
|
| 207 |
+
// If the first digit is now '0' + 10, we would need to set it to '0' and add
|
| 208 |
+
// a '1' in front. However we reach the first digit only if all following
|
| 209 |
+
// digits had been '9' before rounding up. Now all trailing digits are '0' and
|
| 210 |
+
// we simply switch the first digit to '1' and update the decimal-point
|
| 211 |
+
// (indicating that the point is now one digit to the right).
|
| 212 |
+
if (buffer[0] == '0' + 10) {
|
| 213 |
+
buffer[0] = '1';
|
| 214 |
+
(*decimal_point)++;
|
| 215 |
+
}
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
// The given fractionals number represents a fixed-point number with binary
|
| 220 |
+
// point at bit (-exponent).
|
| 221 |
+
// Preconditions:
|
| 222 |
+
// -128 <= exponent <= 0.
|
| 223 |
+
// 0 <= fractionals * 2^exponent < 1
|
| 224 |
+
// The buffer holds the result.
|
| 225 |
+
// The function will round its result. During the rounding-process digits not
|
| 226 |
+
// generated by this function might be updated, and the decimal-point variable
|
| 227 |
+
// might be updated. If this function generates the digits 99 and the buffer
|
| 228 |
+
// already contained "199" (thus yielding a buffer of "19999") then a
|
| 229 |
+
// rounding-up will change the contents of the buffer to "20000".
|
| 230 |
+
static void FillFractionals(uint64_t fractionals, int exponent,
|
| 231 |
+
int fractional_count, Vector<char> buffer,
|
| 232 |
+
int* length, int* decimal_point) {
|
| 233 |
+
DOUBLE_CONVERSION_ASSERT(-128 <= exponent && exponent <= 0);
|
| 234 |
+
// 'fractionals' is a fixed-point number, with binary point at bit
|
| 235 |
+
// (-exponent). Inside the function the non-converted remainder of fractionals
|
| 236 |
+
// is a fixed-point number, with binary point at bit 'point'.
|
| 237 |
+
if (-exponent <= 64) {
|
| 238 |
+
// One 64 bit number is sufficient.
|
| 239 |
+
DOUBLE_CONVERSION_ASSERT(fractionals >> 56 == 0);
|
| 240 |
+
int point = -exponent;
|
| 241 |
+
for (int i = 0; i < fractional_count; ++i) {
|
| 242 |
+
if (fractionals == 0) break;
|
| 243 |
+
// Instead of multiplying by 10 we multiply by 5 and adjust the point
|
| 244 |
+
// location. This way the fractionals variable will not overflow.
|
| 245 |
+
// Invariant at the beginning of the loop: fractionals < 2^point.
|
| 246 |
+
// Initially we have: point <= 64 and fractionals < 2^56
|
| 247 |
+
// After each iteration the point is decremented by one.
|
| 248 |
+
// Note that 5^3 = 125 < 128 = 2^7.
|
| 249 |
+
// Therefore three iterations of this loop will not overflow fractionals
|
| 250 |
+
// (even without the subtraction at the end of the loop body). At this
|
| 251 |
+
// time point will satisfy point <= 61 and therefore fractionals < 2^point
|
| 252 |
+
// and any further multiplication of fractionals by 5 will not overflow.
|
| 253 |
+
fractionals *= 5;
|
| 254 |
+
point--;
|
| 255 |
+
int digit = static_cast<int>(fractionals >> point);
|
| 256 |
+
DOUBLE_CONVERSION_ASSERT(digit <= 9);
|
| 257 |
+
buffer[*length] = static_cast<char>('0' + digit);
|
| 258 |
+
(*length)++;
|
| 259 |
+
fractionals -= static_cast<uint64_t>(digit) << point;
|
| 260 |
+
}
|
| 261 |
+
// If the first bit after the point is set we have to round up.
|
| 262 |
+
DOUBLE_CONVERSION_ASSERT(fractionals == 0 || point - 1 >= 0);
|
| 263 |
+
if ((fractionals != 0) && ((fractionals >> (point - 1)) & 1) == 1) {
|
| 264 |
+
RoundUp(buffer, length, decimal_point);
|
| 265 |
+
}
|
| 266 |
+
} else { // We need 128 bits.
|
| 267 |
+
DOUBLE_CONVERSION_ASSERT(64 < -exponent && -exponent <= 128);
|
| 268 |
+
UInt128 fractionals128 = UInt128(fractionals, 0);
|
| 269 |
+
fractionals128.Shift(-exponent - 64);
|
| 270 |
+
int point = 128;
|
| 271 |
+
for (int i = 0; i < fractional_count; ++i) {
|
| 272 |
+
if (fractionals128.IsZero()) break;
|
| 273 |
+
// As before: instead of multiplying by 10 we multiply by 5 and adjust the
|
| 274 |
+
// point location.
|
| 275 |
+
// This multiplication will not overflow for the same reasons as before.
|
| 276 |
+
fractionals128.Multiply(5);
|
| 277 |
+
point--;
|
| 278 |
+
int digit = fractionals128.DivModPowerOf2(point);
|
| 279 |
+
DOUBLE_CONVERSION_ASSERT(digit <= 9);
|
| 280 |
+
buffer[*length] = static_cast<char>('0' + digit);
|
| 281 |
+
(*length)++;
|
| 282 |
+
}
|
| 283 |
+
if (fractionals128.BitAt(point - 1) == 1) {
|
| 284 |
+
RoundUp(buffer, length, decimal_point);
|
| 285 |
+
}
|
| 286 |
+
}
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
// Removes leading and trailing zeros.
|
| 291 |
+
// If leading zeros are removed then the decimal point position is adjusted.
|
| 292 |
+
static void TrimZeros(Vector<char> buffer, int* length, int* decimal_point) {
|
| 293 |
+
while (*length > 0 && buffer[(*length) - 1] == '0') {
|
| 294 |
+
(*length)--;
|
| 295 |
+
}
|
| 296 |
+
int first_non_zero = 0;
|
| 297 |
+
while (first_non_zero < *length && buffer[first_non_zero] == '0') {
|
| 298 |
+
first_non_zero++;
|
| 299 |
+
}
|
| 300 |
+
if (first_non_zero != 0) {
|
| 301 |
+
for (int i = first_non_zero; i < *length; ++i) {
|
| 302 |
+
buffer[i - first_non_zero] = buffer[i];
|
| 303 |
+
}
|
| 304 |
+
*length -= first_non_zero;
|
| 305 |
+
*decimal_point -= first_non_zero;
|
| 306 |
+
}
|
| 307 |
+
}
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
bool FastFixedDtoa(double v,
|
| 311 |
+
int fractional_count,
|
| 312 |
+
Vector<char> buffer,
|
| 313 |
+
int* length,
|
| 314 |
+
int* decimal_point) {
|
| 315 |
+
const uint32_t kMaxUInt32 = 0xFFFFFFFF;
|
| 316 |
+
uint64_t significand = Double(v).Significand();
|
| 317 |
+
int exponent = Double(v).Exponent();
|
| 318 |
+
// v = significand * 2^exponent (with significand a 53bit integer).
|
| 319 |
+
// If the exponent is larger than 20 (i.e. we may have a 73bit number) then we
|
| 320 |
+
// don't know how to compute the representation. 2^73 ~= 9.5*10^21.
|
| 321 |
+
// If necessary this limit could probably be increased, but we don't need
|
| 322 |
+
// more.
|
| 323 |
+
if (exponent > 20) return false;
|
| 324 |
+
if (fractional_count > 20) return false;
|
| 325 |
+
*length = 0;
|
| 326 |
+
// At most kDoubleSignificandSize bits of the significand are non-zero.
|
| 327 |
+
// Given a 64 bit integer we have 11 0s followed by 53 potentially non-zero
|
| 328 |
+
// bits: 0..11*..0xxx..53*..xx
|
| 329 |
+
if (exponent + kDoubleSignificandSize > 64) {
|
| 330 |
+
// The exponent must be > 11.
|
| 331 |
+
//
|
| 332 |
+
// We know that v = significand * 2^exponent.
|
| 333 |
+
// And the exponent > 11.
|
| 334 |
+
// We simplify the task by dividing v by 10^17.
|
| 335 |
+
// The quotient delivers the first digits, and the remainder fits into a 64
|
| 336 |
+
// bit number.
|
| 337 |
+
// Dividing by 10^17 is equivalent to dividing by 5^17*2^17.
|
| 338 |
+
const uint64_t kFive17 = DOUBLE_CONVERSION_UINT64_2PART_C(0xB1, A2BC2EC5); // 5^17
|
| 339 |
+
uint64_t divisor = kFive17;
|
| 340 |
+
int divisor_power = 17;
|
| 341 |
+
uint64_t dividend = significand;
|
| 342 |
+
uint32_t quotient;
|
| 343 |
+
uint64_t remainder;
|
| 344 |
+
// Let v = f * 2^e with f == significand and e == exponent.
|
| 345 |
+
// Then need q (quotient) and r (remainder) as follows:
|
| 346 |
+
// v = q * 10^17 + r
|
| 347 |
+
// f * 2^e = q * 10^17 + r
|
| 348 |
+
// f * 2^e = q * 5^17 * 2^17 + r
|
| 349 |
+
// If e > 17 then
|
| 350 |
+
// f * 2^(e-17) = q * 5^17 + r/2^17
|
| 351 |
+
// else
|
| 352 |
+
// f = q * 5^17 * 2^(17-e) + r/2^e
|
| 353 |
+
if (exponent > divisor_power) {
|
| 354 |
+
// We only allow exponents of up to 20 and therefore (17 - e) <= 3
|
| 355 |
+
dividend <<= exponent - divisor_power;
|
| 356 |
+
quotient = static_cast<uint32_t>(dividend / divisor);
|
| 357 |
+
remainder = (dividend % divisor) << divisor_power;
|
| 358 |
+
} else {
|
| 359 |
+
divisor <<= divisor_power - exponent;
|
| 360 |
+
quotient = static_cast<uint32_t>(dividend / divisor);
|
| 361 |
+
remainder = (dividend % divisor) << exponent;
|
| 362 |
+
}
|
| 363 |
+
FillDigits32(quotient, buffer, length);
|
| 364 |
+
FillDigits64FixedLength(remainder, buffer, length);
|
| 365 |
+
*decimal_point = *length;
|
| 366 |
+
} else if (exponent >= 0) {
|
| 367 |
+
// 0 <= exponent <= 11
|
| 368 |
+
significand <<= exponent;
|
| 369 |
+
FillDigits64(significand, buffer, length);
|
| 370 |
+
*decimal_point = *length;
|
| 371 |
+
} else if (exponent > -kDoubleSignificandSize) {
|
| 372 |
+
// We have to cut the number.
|
| 373 |
+
uint64_t integrals = significand >> -exponent;
|
| 374 |
+
uint64_t fractionals = significand - (integrals << -exponent);
|
| 375 |
+
if (integrals > kMaxUInt32) {
|
| 376 |
+
FillDigits64(integrals, buffer, length);
|
| 377 |
+
} else {
|
| 378 |
+
FillDigits32(static_cast<uint32_t>(integrals), buffer, length);
|
| 379 |
+
}
|
| 380 |
+
*decimal_point = *length;
|
| 381 |
+
FillFractionals(fractionals, exponent, fractional_count,
|
| 382 |
+
buffer, length, decimal_point);
|
| 383 |
+
} else if (exponent < -128) {
|
| 384 |
+
// This configuration (with at most 20 digits) means that all digits must be
|
| 385 |
+
// 0.
|
| 386 |
+
DOUBLE_CONVERSION_ASSERT(fractional_count <= 20);
|
| 387 |
+
buffer[0] = '\0';
|
| 388 |
+
*length = 0;
|
| 389 |
+
*decimal_point = -fractional_count;
|
| 390 |
+
} else {
|
| 391 |
+
*decimal_point = 0;
|
| 392 |
+
FillFractionals(significand, exponent, fractional_count,
|
| 393 |
+
buffer, length, decimal_point);
|
| 394 |
+
}
|
| 395 |
+
TrimZeros(buffer, length, decimal_point);
|
| 396 |
+
buffer[*length] = '\0';
|
| 397 |
+
if ((*length) == 0) {
|
| 398 |
+
// The string is empty and the decimal_point thus has no importance. Mimic
|
| 399 |
+
// Gay's dtoa and set it to -fractional_count.
|
| 400 |
+
*decimal_point = -fractional_count;
|
| 401 |
+
}
|
| 402 |
+
return true;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
} // namespace double_conversion
|
cpp-compiled/sources/double-conversion/fixed-dtoa.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/gay-fixed.cc
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/gay-precision.cc
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/gay-shortest-single.cc
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/gay-shortest.cc
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/string-to-double.cc
ADDED
|
@@ -0,0 +1,818 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2010 the V8 project authors. All rights reserved.
|
| 2 |
+
// Redistribution and use in source and binary forms, with or without
|
| 3 |
+
// modification, are permitted provided that the following conditions are
|
| 4 |
+
// met:
|
| 5 |
+
//
|
| 6 |
+
// * Redistributions of source code must retain the above copyright
|
| 7 |
+
// notice, this list of conditions and the following disclaimer.
|
| 8 |
+
// * Redistributions in binary form must reproduce the above
|
| 9 |
+
// copyright notice, this list of conditions and the following
|
| 10 |
+
// disclaimer in the documentation and/or other materials provided
|
| 11 |
+
// with the distribution.
|
| 12 |
+
// * Neither the name of Google Inc. nor the names of its
|
| 13 |
+
// contributors may be used to endorse or promote products derived
|
| 14 |
+
// from this software without specific prior written permission.
|
| 15 |
+
//
|
| 16 |
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 17 |
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 18 |
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 19 |
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 20 |
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 21 |
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 22 |
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 23 |
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 24 |
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 25 |
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 26 |
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 |
+
|
| 28 |
+
#include <climits>
|
| 29 |
+
#include <locale>
|
| 30 |
+
#include <cmath>
|
| 31 |
+
|
| 32 |
+
#include "string-to-double.h"
|
| 33 |
+
|
| 34 |
+
#include "ieee.h"
|
| 35 |
+
#include "strtod.h"
|
| 36 |
+
#include "utils.h"
|
| 37 |
+
|
| 38 |
+
#ifdef _MSC_VER
|
| 39 |
+
# if _MSC_VER >= 1900
|
| 40 |
+
// Fix MSVC >= 2015 (_MSC_VER == 1900) warning
|
| 41 |
+
// C4244: 'argument': conversion from 'const uc16' to 'char', possible loss of data
|
| 42 |
+
// against Advance and friends, when instantiated with **it as char, not uc16.
|
| 43 |
+
__pragma(warning(disable: 4244))
|
| 44 |
+
# endif
|
| 45 |
+
# if _MSC_VER <= 1700 // VS2012, see IsDecimalDigitForRadix warning fix, below
|
| 46 |
+
# define VS2012_RADIXWARN
|
| 47 |
+
# endif
|
| 48 |
+
#endif
|
| 49 |
+
|
| 50 |
+
namespace double_conversion {
|
| 51 |
+
|
| 52 |
+
namespace {
|
| 53 |
+
|
| 54 |
+
inline char ToLower(char ch) {
|
| 55 |
+
static const std::ctype<char>& cType =
|
| 56 |
+
std::use_facet<std::ctype<char> >(std::locale::classic());
|
| 57 |
+
return cType.tolower(ch);
|
| 58 |
+
}
|
| 59 |
+
|
| 60 |
+
inline char Pass(char ch) {
|
| 61 |
+
return ch;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
template <class Iterator, class Converter>
|
| 65 |
+
static inline bool ConsumeSubStringImpl(Iterator* current,
|
| 66 |
+
Iterator end,
|
| 67 |
+
const char* substring,
|
| 68 |
+
Converter converter) {
|
| 69 |
+
DOUBLE_CONVERSION_ASSERT(converter(**current) == *substring);
|
| 70 |
+
for (substring++; *substring != '\0'; substring++) {
|
| 71 |
+
++*current;
|
| 72 |
+
if (*current == end || converter(**current) != *substring) {
|
| 73 |
+
return false;
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
++*current;
|
| 77 |
+
return true;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
// Consumes the given substring from the iterator.
|
| 81 |
+
// Returns false, if the substring does not match.
|
| 82 |
+
template <class Iterator>
|
| 83 |
+
static bool ConsumeSubString(Iterator* current,
|
| 84 |
+
Iterator end,
|
| 85 |
+
const char* substring,
|
| 86 |
+
bool allow_case_insensitivity) {
|
| 87 |
+
if (allow_case_insensitivity) {
|
| 88 |
+
return ConsumeSubStringImpl(current, end, substring, ToLower);
|
| 89 |
+
} else {
|
| 90 |
+
return ConsumeSubStringImpl(current, end, substring, Pass);
|
| 91 |
+
}
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
// Consumes first character of the str is equal to ch
|
| 95 |
+
inline bool ConsumeFirstCharacter(char ch,
|
| 96 |
+
const char* str,
|
| 97 |
+
bool case_insensitivity) {
|
| 98 |
+
return case_insensitivity ? ToLower(ch) == str[0] : ch == str[0];
|
| 99 |
+
}
|
| 100 |
+
} // namespace
|
| 101 |
+
|
| 102 |
+
// Maximum number of significant digits in decimal representation.
|
| 103 |
+
// The longest possible double in decimal representation is
|
| 104 |
+
// (2^53 - 1) * 2 ^ -1074 that is (2 ^ 53 - 1) * 5 ^ 1074 / 10 ^ 1074
|
| 105 |
+
// (768 digits). If we parse a number whose first digits are equal to a
|
| 106 |
+
// mean of 2 adjacent doubles (that could have up to 769 digits) the result
|
| 107 |
+
// must be rounded to the bigger one unless the tail consists of zeros, so
|
| 108 |
+
// we don't need to preserve all the digits.
|
| 109 |
+
const int kMaxSignificantDigits = 772;
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
static const char kWhitespaceTable7[] = { 32, 13, 10, 9, 11, 12 };
|
| 113 |
+
static const int kWhitespaceTable7Length = DOUBLE_CONVERSION_ARRAY_SIZE(kWhitespaceTable7);
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
static const uc16 kWhitespaceTable16[] = {
|
| 117 |
+
160, 8232, 8233, 5760, 6158, 8192, 8193, 8194, 8195,
|
| 118 |
+
8196, 8197, 8198, 8199, 8200, 8201, 8202, 8239, 8287, 12288, 65279
|
| 119 |
+
};
|
| 120 |
+
static const int kWhitespaceTable16Length = DOUBLE_CONVERSION_ARRAY_SIZE(kWhitespaceTable16);
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
static bool isWhitespace(int x) {
|
| 124 |
+
if (x < 128) {
|
| 125 |
+
for (int i = 0; i < kWhitespaceTable7Length; i++) {
|
| 126 |
+
if (kWhitespaceTable7[i] == x) return true;
|
| 127 |
+
}
|
| 128 |
+
} else {
|
| 129 |
+
for (int i = 0; i < kWhitespaceTable16Length; i++) {
|
| 130 |
+
if (kWhitespaceTable16[i] == x) return true;
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
return false;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
// Returns true if a nonspace found and false if the end has reached.
|
| 138 |
+
template <class Iterator>
|
| 139 |
+
static inline bool AdvanceToNonspace(Iterator* current, Iterator end) {
|
| 140 |
+
while (*current != end) {
|
| 141 |
+
if (!isWhitespace(**current)) return true;
|
| 142 |
+
++*current;
|
| 143 |
+
}
|
| 144 |
+
return false;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
static bool isDigit(int x, int radix) {
|
| 149 |
+
return (x >= '0' && x <= '9' && x < '0' + radix)
|
| 150 |
+
|| (radix > 10 && x >= 'a' && x < 'a' + radix - 10)
|
| 151 |
+
|| (radix > 10 && x >= 'A' && x < 'A' + radix - 10);
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
static double SignedZero(bool sign) {
|
| 156 |
+
return sign ? -0.0 : 0.0;
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
// Returns true if 'c' is a decimal digit that is valid for the given radix.
|
| 161 |
+
//
|
| 162 |
+
// The function is small and could be inlined, but VS2012 emitted a warning
|
| 163 |
+
// because it constant-propagated the radix and concluded that the last
|
| 164 |
+
// condition was always true. Moving it into a separate function and
|
| 165 |
+
// suppressing optimisation keeps the compiler from warning.
|
| 166 |
+
#ifdef VS2012_RADIXWARN
|
| 167 |
+
#pragma optimize("",off)
|
| 168 |
+
static bool IsDecimalDigitForRadix(int c, int radix) {
|
| 169 |
+
return '0' <= c && c <= '9' && (c - '0') < radix;
|
| 170 |
+
}
|
| 171 |
+
#pragma optimize("",on)
|
| 172 |
+
#else
|
| 173 |
+
static bool inline IsDecimalDigitForRadix(int c, int radix) {
|
| 174 |
+
return '0' <= c && c <= '9' && (c - '0') < radix;
|
| 175 |
+
}
|
| 176 |
+
#endif
|
| 177 |
+
// Returns true if 'c' is a character digit that is valid for the given radix.
|
| 178 |
+
// The 'a_character' should be 'a' or 'A'.
|
| 179 |
+
//
|
| 180 |
+
// The function is small and could be inlined, but VS2012 emitted a warning
|
| 181 |
+
// because it constant-propagated the radix and concluded that the first
|
| 182 |
+
// condition was always false. By moving it into a separate function the
|
| 183 |
+
// compiler wouldn't warn anymore.
|
| 184 |
+
static bool IsCharacterDigitForRadix(int c, int radix, char a_character) {
|
| 185 |
+
return radix > 10 && c >= a_character && c < a_character + radix - 10;
|
| 186 |
+
}
|
| 187 |
+
|
| 188 |
+
// Returns true, when the iterator is equal to end.
|
| 189 |
+
template<class Iterator>
|
| 190 |
+
static bool Advance (Iterator* it, uc16 separator, int base, Iterator& end) {
|
| 191 |
+
if (separator == StringToDoubleConverter::kNoSeparator) {
|
| 192 |
+
++(*it);
|
| 193 |
+
return *it == end;
|
| 194 |
+
}
|
| 195 |
+
if (!isDigit(**it, base)) {
|
| 196 |
+
++(*it);
|
| 197 |
+
return *it == end;
|
| 198 |
+
}
|
| 199 |
+
++(*it);
|
| 200 |
+
if (*it == end) return true;
|
| 201 |
+
if (*it + 1 == end) return false;
|
| 202 |
+
if (**it == separator && isDigit(*(*it + 1), base)) {
|
| 203 |
+
++(*it);
|
| 204 |
+
}
|
| 205 |
+
return *it == end;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
// Checks whether the string in the range start-end is a hex-float string.
|
| 209 |
+
// This function assumes that the leading '0x'/'0X' is already consumed.
|
| 210 |
+
//
|
| 211 |
+
// Hex float strings are of one of the following forms:
|
| 212 |
+
// - hex_digits+ 'p' ('+'|'-')? exponent_digits+
|
| 213 |
+
// - hex_digits* '.' hex_digits+ 'p' ('+'|'-')? exponent_digits+
|
| 214 |
+
// - hex_digits+ '.' 'p' ('+'|'-')? exponent_digits+
|
| 215 |
+
template<class Iterator>
|
| 216 |
+
static bool IsHexFloatString(Iterator start,
|
| 217 |
+
Iterator end,
|
| 218 |
+
uc16 separator,
|
| 219 |
+
bool allow_trailing_junk) {
|
| 220 |
+
DOUBLE_CONVERSION_ASSERT(start != end);
|
| 221 |
+
|
| 222 |
+
Iterator current = start;
|
| 223 |
+
|
| 224 |
+
bool saw_digit = false;
|
| 225 |
+
while (isDigit(*current, 16)) {
|
| 226 |
+
saw_digit = true;
|
| 227 |
+
if (Advance(¤t, separator, 16, end)) return false;
|
| 228 |
+
}
|
| 229 |
+
if (*current == '.') {
|
| 230 |
+
if (Advance(¤t, separator, 16, end)) return false;
|
| 231 |
+
while (isDigit(*current, 16)) {
|
| 232 |
+
saw_digit = true;
|
| 233 |
+
if (Advance(¤t, separator, 16, end)) return false;
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
if (!saw_digit) return false;
|
| 237 |
+
if (*current != 'p' && *current != 'P') return false;
|
| 238 |
+
if (Advance(¤t, separator, 16, end)) return false;
|
| 239 |
+
if (*current == '+' || *current == '-') {
|
| 240 |
+
if (Advance(¤t, separator, 16, end)) return false;
|
| 241 |
+
}
|
| 242 |
+
if (!isDigit(*current, 10)) return false;
|
| 243 |
+
if (Advance(¤t, separator, 16, end)) return true;
|
| 244 |
+
while (isDigit(*current, 10)) {
|
| 245 |
+
if (Advance(¤t, separator, 16, end)) return true;
|
| 246 |
+
}
|
| 247 |
+
return allow_trailing_junk || !AdvanceToNonspace(¤t, end);
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
|
| 251 |
+
// Parsing integers with radix 2, 4, 8, 16, 32. Assumes current != end.
|
| 252 |
+
//
|
| 253 |
+
// If parse_as_hex_float is true, then the string must be a valid
|
| 254 |
+
// hex-float.
|
| 255 |
+
template <int radix_log_2, class Iterator>
|
| 256 |
+
static double RadixStringToIeee(Iterator* current,
|
| 257 |
+
Iterator end,
|
| 258 |
+
bool sign,
|
| 259 |
+
uc16 separator,
|
| 260 |
+
bool parse_as_hex_float,
|
| 261 |
+
bool allow_trailing_junk,
|
| 262 |
+
double junk_string_value,
|
| 263 |
+
bool read_as_double,
|
| 264 |
+
bool* result_is_junk) {
|
| 265 |
+
DOUBLE_CONVERSION_ASSERT(*current != end);
|
| 266 |
+
DOUBLE_CONVERSION_ASSERT(!parse_as_hex_float ||
|
| 267 |
+
IsHexFloatString(*current, end, separator, allow_trailing_junk));
|
| 268 |
+
|
| 269 |
+
const int kDoubleSize = Double::kSignificandSize;
|
| 270 |
+
const int kSingleSize = Single::kSignificandSize;
|
| 271 |
+
const int kSignificandSize = read_as_double? kDoubleSize: kSingleSize;
|
| 272 |
+
|
| 273 |
+
*result_is_junk = true;
|
| 274 |
+
|
| 275 |
+
int64_t number = 0;
|
| 276 |
+
int exponent = 0;
|
| 277 |
+
const int radix = (1 << radix_log_2);
|
| 278 |
+
// Whether we have encountered a '.' and are parsing the decimal digits.
|
| 279 |
+
// Only relevant if parse_as_hex_float is true.
|
| 280 |
+
bool post_decimal = false;
|
| 281 |
+
|
| 282 |
+
// Skip leading 0s.
|
| 283 |
+
while (**current == '0') {
|
| 284 |
+
if (Advance(current, separator, radix, end)) {
|
| 285 |
+
*result_is_junk = false;
|
| 286 |
+
return SignedZero(sign);
|
| 287 |
+
}
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
while (true) {
|
| 291 |
+
int digit;
|
| 292 |
+
if (IsDecimalDigitForRadix(**current, radix)) {
|
| 293 |
+
digit = static_cast<char>(**current) - '0';
|
| 294 |
+
if (post_decimal) exponent -= radix_log_2;
|
| 295 |
+
} else if (IsCharacterDigitForRadix(**current, radix, 'a')) {
|
| 296 |
+
digit = static_cast<char>(**current) - 'a' + 10;
|
| 297 |
+
if (post_decimal) exponent -= radix_log_2;
|
| 298 |
+
} else if (IsCharacterDigitForRadix(**current, radix, 'A')) {
|
| 299 |
+
digit = static_cast<char>(**current) - 'A' + 10;
|
| 300 |
+
if (post_decimal) exponent -= radix_log_2;
|
| 301 |
+
} else if (parse_as_hex_float && **current == '.') {
|
| 302 |
+
post_decimal = true;
|
| 303 |
+
Advance(current, separator, radix, end);
|
| 304 |
+
DOUBLE_CONVERSION_ASSERT(*current != end);
|
| 305 |
+
continue;
|
| 306 |
+
} else if (parse_as_hex_float && (**current == 'p' || **current == 'P')) {
|
| 307 |
+
break;
|
| 308 |
+
} else {
|
| 309 |
+
if (allow_trailing_junk || !AdvanceToNonspace(current, end)) {
|
| 310 |
+
break;
|
| 311 |
+
} else {
|
| 312 |
+
return junk_string_value;
|
| 313 |
+
}
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
number = number * radix + digit;
|
| 317 |
+
int overflow = static_cast<int>(number >> kSignificandSize);
|
| 318 |
+
if (overflow != 0) {
|
| 319 |
+
// Overflow occurred. Need to determine which direction to round the
|
| 320 |
+
// result.
|
| 321 |
+
int overflow_bits_count = 1;
|
| 322 |
+
while (overflow > 1) {
|
| 323 |
+
overflow_bits_count++;
|
| 324 |
+
overflow >>= 1;
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
int dropped_bits_mask = ((1 << overflow_bits_count) - 1);
|
| 328 |
+
int dropped_bits = static_cast<int>(number) & dropped_bits_mask;
|
| 329 |
+
number >>= overflow_bits_count;
|
| 330 |
+
exponent += overflow_bits_count;
|
| 331 |
+
|
| 332 |
+
bool zero_tail = true;
|
| 333 |
+
for (;;) {
|
| 334 |
+
if (Advance(current, separator, radix, end)) break;
|
| 335 |
+
if (parse_as_hex_float && **current == '.') {
|
| 336 |
+
// Just run over the '.'. We are just trying to see whether there is
|
| 337 |
+
// a non-zero digit somewhere.
|
| 338 |
+
Advance(current, separator, radix, end);
|
| 339 |
+
DOUBLE_CONVERSION_ASSERT(*current != end);
|
| 340 |
+
post_decimal = true;
|
| 341 |
+
}
|
| 342 |
+
if (!isDigit(**current, radix)) break;
|
| 343 |
+
zero_tail = zero_tail && **current == '0';
|
| 344 |
+
if (!post_decimal) exponent += radix_log_2;
|
| 345 |
+
}
|
| 346 |
+
|
| 347 |
+
if (!parse_as_hex_float &&
|
| 348 |
+
!allow_trailing_junk &&
|
| 349 |
+
AdvanceToNonspace(current, end)) {
|
| 350 |
+
return junk_string_value;
|
| 351 |
+
}
|
| 352 |
+
|
| 353 |
+
int middle_value = (1 << (overflow_bits_count - 1));
|
| 354 |
+
if (dropped_bits > middle_value) {
|
| 355 |
+
number++; // Rounding up.
|
| 356 |
+
} else if (dropped_bits == middle_value) {
|
| 357 |
+
// Rounding to even to consistency with decimals: half-way case rounds
|
| 358 |
+
// up if significant part is odd and down otherwise.
|
| 359 |
+
if ((number & 1) != 0 || !zero_tail) {
|
| 360 |
+
number++; // Rounding up.
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
// Rounding up may cause overflow.
|
| 365 |
+
if ((number & ((int64_t)1 << kSignificandSize)) != 0) {
|
| 366 |
+
exponent++;
|
| 367 |
+
number >>= 1;
|
| 368 |
+
}
|
| 369 |
+
break;
|
| 370 |
+
}
|
| 371 |
+
if (Advance(current, separator, radix, end)) break;
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
DOUBLE_CONVERSION_ASSERT(number < ((int64_t)1 << kSignificandSize));
|
| 375 |
+
DOUBLE_CONVERSION_ASSERT(static_cast<int64_t>(static_cast<double>(number)) == number);
|
| 376 |
+
|
| 377 |
+
*result_is_junk = false;
|
| 378 |
+
|
| 379 |
+
if (parse_as_hex_float) {
|
| 380 |
+
DOUBLE_CONVERSION_ASSERT(**current == 'p' || **current == 'P');
|
| 381 |
+
Advance(current, separator, radix, end);
|
| 382 |
+
DOUBLE_CONVERSION_ASSERT(*current != end);
|
| 383 |
+
bool is_negative = false;
|
| 384 |
+
if (**current == '+') {
|
| 385 |
+
Advance(current, separator, radix, end);
|
| 386 |
+
DOUBLE_CONVERSION_ASSERT(*current != end);
|
| 387 |
+
} else if (**current == '-') {
|
| 388 |
+
is_negative = true;
|
| 389 |
+
Advance(current, separator, radix, end);
|
| 390 |
+
DOUBLE_CONVERSION_ASSERT(*current != end);
|
| 391 |
+
}
|
| 392 |
+
int written_exponent = 0;
|
| 393 |
+
while (IsDecimalDigitForRadix(**current, 10)) {
|
| 394 |
+
// No need to read exponents if they are too big. That could potentially overflow
|
| 395 |
+
// the `written_exponent` variable.
|
| 396 |
+
if (abs(written_exponent) <= 100 * Double::kMaxExponent) {
|
| 397 |
+
written_exponent = 10 * written_exponent + **current - '0';
|
| 398 |
+
}
|
| 399 |
+
if (Advance(current, separator, radix, end)) break;
|
| 400 |
+
}
|
| 401 |
+
if (is_negative) written_exponent = -written_exponent;
|
| 402 |
+
exponent += written_exponent;
|
| 403 |
+
}
|
| 404 |
+
|
| 405 |
+
if (exponent == 0 || number == 0) {
|
| 406 |
+
if (sign) {
|
| 407 |
+
if (number == 0) return -0.0;
|
| 408 |
+
number = -number;
|
| 409 |
+
}
|
| 410 |
+
return static_cast<double>(number);
|
| 411 |
+
}
|
| 412 |
+
|
| 413 |
+
DOUBLE_CONVERSION_ASSERT(number != 0);
|
| 414 |
+
double result = Double(DiyFp(number, exponent)).value();
|
| 415 |
+
return sign ? -result : result;
|
| 416 |
+
}
|
| 417 |
+
|
| 418 |
+
template <class Iterator>
|
| 419 |
+
double StringToDoubleConverter::StringToIeee(
|
| 420 |
+
Iterator input,
|
| 421 |
+
int length,
|
| 422 |
+
bool read_as_double,
|
| 423 |
+
int* processed_characters_count) const {
|
| 424 |
+
Iterator current = input;
|
| 425 |
+
Iterator end = input + length;
|
| 426 |
+
|
| 427 |
+
*processed_characters_count = 0;
|
| 428 |
+
|
| 429 |
+
const bool allow_trailing_junk = (flags_ & ALLOW_TRAILING_JUNK) != 0;
|
| 430 |
+
const bool allow_leading_spaces = (flags_ & ALLOW_LEADING_SPACES) != 0;
|
| 431 |
+
const bool allow_trailing_spaces = (flags_ & ALLOW_TRAILING_SPACES) != 0;
|
| 432 |
+
const bool allow_spaces_after_sign = (flags_ & ALLOW_SPACES_AFTER_SIGN) != 0;
|
| 433 |
+
const bool allow_case_insensitivity = (flags_ & ALLOW_CASE_INSENSITIVITY) != 0;
|
| 434 |
+
|
| 435 |
+
// To make sure that iterator dereferencing is valid the following
|
| 436 |
+
// convention is used:
|
| 437 |
+
// 1. Each '++current' statement is followed by check for equality to 'end'.
|
| 438 |
+
// 2. If AdvanceToNonspace returned false then current == end.
|
| 439 |
+
// 3. If 'current' becomes equal to 'end' the function returns or goes to
|
| 440 |
+
// 'parsing_done'.
|
| 441 |
+
// 4. 'current' is not dereferenced after the 'parsing_done' label.
|
| 442 |
+
// 5. Code before 'parsing_done' may rely on 'current != end'.
|
| 443 |
+
if (current == end) return empty_string_value_;
|
| 444 |
+
|
| 445 |
+
if (allow_leading_spaces || allow_trailing_spaces) {
|
| 446 |
+
if (!AdvanceToNonspace(¤t, end)) {
|
| 447 |
+
*processed_characters_count = static_cast<int>(current - input);
|
| 448 |
+
return empty_string_value_;
|
| 449 |
+
}
|
| 450 |
+
if (!allow_leading_spaces && (input != current)) {
|
| 451 |
+
// No leading spaces allowed, but AdvanceToNonspace moved forward.
|
| 452 |
+
return junk_string_value_;
|
| 453 |
+
}
|
| 454 |
+
}
|
| 455 |
+
|
| 456 |
+
// Exponent will be adjusted if insignificant digits of the integer part
|
| 457 |
+
// or insignificant leading zeros of the fractional part are dropped.
|
| 458 |
+
int exponent = 0;
|
| 459 |
+
int significant_digits = 0;
|
| 460 |
+
int insignificant_digits = 0;
|
| 461 |
+
bool nonzero_digit_dropped = false;
|
| 462 |
+
|
| 463 |
+
bool sign = false;
|
| 464 |
+
|
| 465 |
+
if (*current == '+' || *current == '-') {
|
| 466 |
+
sign = (*current == '-');
|
| 467 |
+
++current;
|
| 468 |
+
Iterator next_non_space = current;
|
| 469 |
+
// Skip following spaces (if allowed).
|
| 470 |
+
if (!AdvanceToNonspace(&next_non_space, end)) return junk_string_value_;
|
| 471 |
+
if (!allow_spaces_after_sign && (current != next_non_space)) {
|
| 472 |
+
return junk_string_value_;
|
| 473 |
+
}
|
| 474 |
+
current = next_non_space;
|
| 475 |
+
}
|
| 476 |
+
|
| 477 |
+
if (infinity_symbol_ != DOUBLE_CONVERSION_NULLPTR) {
|
| 478 |
+
if (ConsumeFirstCharacter(*current, infinity_symbol_, allow_case_insensitivity)) {
|
| 479 |
+
if (!ConsumeSubString(¤t, end, infinity_symbol_, allow_case_insensitivity)) {
|
| 480 |
+
return junk_string_value_;
|
| 481 |
+
}
|
| 482 |
+
|
| 483 |
+
if (!(allow_trailing_spaces || allow_trailing_junk) && (current != end)) {
|
| 484 |
+
return junk_string_value_;
|
| 485 |
+
}
|
| 486 |
+
if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) {
|
| 487 |
+
return junk_string_value_;
|
| 488 |
+
}
|
| 489 |
+
|
| 490 |
+
*processed_characters_count = static_cast<int>(current - input);
|
| 491 |
+
return sign ? -Double::Infinity() : Double::Infinity();
|
| 492 |
+
}
|
| 493 |
+
}
|
| 494 |
+
|
| 495 |
+
if (nan_symbol_ != DOUBLE_CONVERSION_NULLPTR) {
|
| 496 |
+
if (ConsumeFirstCharacter(*current, nan_symbol_, allow_case_insensitivity)) {
|
| 497 |
+
if (!ConsumeSubString(¤t, end, nan_symbol_, allow_case_insensitivity)) {
|
| 498 |
+
return junk_string_value_;
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
if (!(allow_trailing_spaces || allow_trailing_junk) && (current != end)) {
|
| 502 |
+
return junk_string_value_;
|
| 503 |
+
}
|
| 504 |
+
if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) {
|
| 505 |
+
return junk_string_value_;
|
| 506 |
+
}
|
| 507 |
+
|
| 508 |
+
*processed_characters_count = static_cast<int>(current - input);
|
| 509 |
+
return sign ? -Double::NaN() : Double::NaN();
|
| 510 |
+
}
|
| 511 |
+
}
|
| 512 |
+
|
| 513 |
+
bool leading_zero = false;
|
| 514 |
+
if (*current == '0') {
|
| 515 |
+
if (Advance(¤t, separator_, 10, end)) {
|
| 516 |
+
*processed_characters_count = static_cast<int>(current - input);
|
| 517 |
+
return SignedZero(sign);
|
| 518 |
+
}
|
| 519 |
+
|
| 520 |
+
leading_zero = true;
|
| 521 |
+
|
| 522 |
+
// It could be hexadecimal value.
|
| 523 |
+
if (((flags_ & ALLOW_HEX) || (flags_ & ALLOW_HEX_FLOATS)) &&
|
| 524 |
+
(*current == 'x' || *current == 'X')) {
|
| 525 |
+
++current;
|
| 526 |
+
|
| 527 |
+
if (current == end) return junk_string_value_; // "0x"
|
| 528 |
+
|
| 529 |
+
bool parse_as_hex_float = (flags_ & ALLOW_HEX_FLOATS) &&
|
| 530 |
+
IsHexFloatString(current, end, separator_, allow_trailing_junk);
|
| 531 |
+
|
| 532 |
+
if (!parse_as_hex_float && !isDigit(*current, 16)) {
|
| 533 |
+
return junk_string_value_;
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
bool result_is_junk;
|
| 537 |
+
double result = RadixStringToIeee<4>(¤t,
|
| 538 |
+
end,
|
| 539 |
+
sign,
|
| 540 |
+
separator_,
|
| 541 |
+
parse_as_hex_float,
|
| 542 |
+
allow_trailing_junk,
|
| 543 |
+
junk_string_value_,
|
| 544 |
+
read_as_double,
|
| 545 |
+
&result_is_junk);
|
| 546 |
+
if (!result_is_junk) {
|
| 547 |
+
if (allow_trailing_spaces) AdvanceToNonspace(¤t, end);
|
| 548 |
+
*processed_characters_count = static_cast<int>(current - input);
|
| 549 |
+
}
|
| 550 |
+
return result;
|
| 551 |
+
}
|
| 552 |
+
|
| 553 |
+
// Ignore leading zeros in the integer part.
|
| 554 |
+
while (*current == '0') {
|
| 555 |
+
if (Advance(¤t, separator_, 10, end)) {
|
| 556 |
+
*processed_characters_count = static_cast<int>(current - input);
|
| 557 |
+
return SignedZero(sign);
|
| 558 |
+
}
|
| 559 |
+
}
|
| 560 |
+
}
|
| 561 |
+
|
| 562 |
+
bool octal = leading_zero && (flags_ & ALLOW_OCTALS) != 0;
|
| 563 |
+
|
| 564 |
+
// The longest form of simplified number is: "-<significant digits>.1eXXX\0".
|
| 565 |
+
const int kBufferSize = kMaxSignificantDigits + 10;
|
| 566 |
+
DOUBLE_CONVERSION_STACK_UNINITIALIZED char
|
| 567 |
+
buffer[kBufferSize]; // NOLINT: size is known at compile time.
|
| 568 |
+
int buffer_pos = 0;
|
| 569 |
+
|
| 570 |
+
// Copy significant digits of the integer part (if any) to the buffer.
|
| 571 |
+
while (*current >= '0' && *current <= '9') {
|
| 572 |
+
if (significant_digits < kMaxSignificantDigits) {
|
| 573 |
+
DOUBLE_CONVERSION_ASSERT(buffer_pos < kBufferSize);
|
| 574 |
+
buffer[buffer_pos++] = static_cast<char>(*current);
|
| 575 |
+
significant_digits++;
|
| 576 |
+
// Will later check if it's an octal in the buffer.
|
| 577 |
+
} else {
|
| 578 |
+
insignificant_digits++; // Move the digit into the exponential part.
|
| 579 |
+
nonzero_digit_dropped = nonzero_digit_dropped || *current != '0';
|
| 580 |
+
}
|
| 581 |
+
octal = octal && *current < '8';
|
| 582 |
+
if (Advance(¤t, separator_, 10, end)) goto parsing_done;
|
| 583 |
+
}
|
| 584 |
+
|
| 585 |
+
if (significant_digits == 0) {
|
| 586 |
+
octal = false;
|
| 587 |
+
}
|
| 588 |
+
|
| 589 |
+
if (*current == '.') {
|
| 590 |
+
if (octal && !allow_trailing_junk) return junk_string_value_;
|
| 591 |
+
if (octal) goto parsing_done;
|
| 592 |
+
|
| 593 |
+
if (Advance(¤t, separator_, 10, end)) {
|
| 594 |
+
if (significant_digits == 0 && !leading_zero) {
|
| 595 |
+
return junk_string_value_;
|
| 596 |
+
} else {
|
| 597 |
+
goto parsing_done;
|
| 598 |
+
}
|
| 599 |
+
}
|
| 600 |
+
|
| 601 |
+
if (significant_digits == 0) {
|
| 602 |
+
// octal = false;
|
| 603 |
+
// Integer part consists of 0 or is absent. Significant digits start after
|
| 604 |
+
// leading zeros (if any).
|
| 605 |
+
while (*current == '0') {
|
| 606 |
+
if (Advance(¤t, separator_, 10, end)) {
|
| 607 |
+
*processed_characters_count = static_cast<int>(current - input);
|
| 608 |
+
return SignedZero(sign);
|
| 609 |
+
}
|
| 610 |
+
exponent--; // Move this 0 into the exponent.
|
| 611 |
+
}
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
// There is a fractional part.
|
| 615 |
+
// We don't emit a '.', but adjust the exponent instead.
|
| 616 |
+
while (*current >= '0' && *current <= '9') {
|
| 617 |
+
if (significant_digits < kMaxSignificantDigits) {
|
| 618 |
+
DOUBLE_CONVERSION_ASSERT(buffer_pos < kBufferSize);
|
| 619 |
+
buffer[buffer_pos++] = static_cast<char>(*current);
|
| 620 |
+
significant_digits++;
|
| 621 |
+
exponent--;
|
| 622 |
+
} else {
|
| 623 |
+
// Ignore insignificant digits in the fractional part.
|
| 624 |
+
nonzero_digit_dropped = nonzero_digit_dropped || *current != '0';
|
| 625 |
+
}
|
| 626 |
+
if (Advance(¤t, separator_, 10, end)) goto parsing_done;
|
| 627 |
+
}
|
| 628 |
+
}
|
| 629 |
+
|
| 630 |
+
if (!leading_zero && exponent == 0 && significant_digits == 0) {
|
| 631 |
+
// If leading_zeros is true then the string contains zeros.
|
| 632 |
+
// If exponent < 0 then string was [+-]\.0*...
|
| 633 |
+
// If significant_digits != 0 the string is not equal to 0.
|
| 634 |
+
// Otherwise there are no digits in the string.
|
| 635 |
+
return junk_string_value_;
|
| 636 |
+
}
|
| 637 |
+
|
| 638 |
+
// Parse exponential part.
|
| 639 |
+
if (*current == 'e' || *current == 'E') {
|
| 640 |
+
if (octal && !allow_trailing_junk) return junk_string_value_;
|
| 641 |
+
if (octal) goto parsing_done;
|
| 642 |
+
Iterator junk_begin = current;
|
| 643 |
+
++current;
|
| 644 |
+
if (current == end) {
|
| 645 |
+
if (allow_trailing_junk) {
|
| 646 |
+
current = junk_begin;
|
| 647 |
+
goto parsing_done;
|
| 648 |
+
} else {
|
| 649 |
+
return junk_string_value_;
|
| 650 |
+
}
|
| 651 |
+
}
|
| 652 |
+
char exponen_sign = '+';
|
| 653 |
+
if (*current == '+' || *current == '-') {
|
| 654 |
+
exponen_sign = static_cast<char>(*current);
|
| 655 |
+
++current;
|
| 656 |
+
if (current == end) {
|
| 657 |
+
if (allow_trailing_junk) {
|
| 658 |
+
current = junk_begin;
|
| 659 |
+
goto parsing_done;
|
| 660 |
+
} else {
|
| 661 |
+
return junk_string_value_;
|
| 662 |
+
}
|
| 663 |
+
}
|
| 664 |
+
}
|
| 665 |
+
|
| 666 |
+
if (current == end || *current < '0' || *current > '9') {
|
| 667 |
+
if (allow_trailing_junk) {
|
| 668 |
+
current = junk_begin;
|
| 669 |
+
goto parsing_done;
|
| 670 |
+
} else {
|
| 671 |
+
return junk_string_value_;
|
| 672 |
+
}
|
| 673 |
+
}
|
| 674 |
+
|
| 675 |
+
const int max_exponent = INT_MAX / 2;
|
| 676 |
+
DOUBLE_CONVERSION_ASSERT(-max_exponent / 2 <= exponent && exponent <= max_exponent / 2);
|
| 677 |
+
int num = 0;
|
| 678 |
+
do {
|
| 679 |
+
// Check overflow.
|
| 680 |
+
int digit = *current - '0';
|
| 681 |
+
if (num >= max_exponent / 10
|
| 682 |
+
&& !(num == max_exponent / 10 && digit <= max_exponent % 10)) {
|
| 683 |
+
num = max_exponent;
|
| 684 |
+
} else {
|
| 685 |
+
num = num * 10 + digit;
|
| 686 |
+
}
|
| 687 |
+
++current;
|
| 688 |
+
} while (current != end && *current >= '0' && *current <= '9');
|
| 689 |
+
|
| 690 |
+
exponent += (exponen_sign == '-' ? -num : num);
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
if (!(allow_trailing_spaces || allow_trailing_junk) && (current != end)) {
|
| 694 |
+
return junk_string_value_;
|
| 695 |
+
}
|
| 696 |
+
if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) {
|
| 697 |
+
return junk_string_value_;
|
| 698 |
+
}
|
| 699 |
+
if (allow_trailing_spaces) {
|
| 700 |
+
AdvanceToNonspace(¤t, end);
|
| 701 |
+
}
|
| 702 |
+
|
| 703 |
+
parsing_done:
|
| 704 |
+
exponent += insignificant_digits;
|
| 705 |
+
|
| 706 |
+
if (octal) {
|
| 707 |
+
double result;
|
| 708 |
+
bool result_is_junk;
|
| 709 |
+
char* start = buffer;
|
| 710 |
+
result = RadixStringToIeee<3>(&start,
|
| 711 |
+
buffer + buffer_pos,
|
| 712 |
+
sign,
|
| 713 |
+
separator_,
|
| 714 |
+
false, // Don't parse as hex_float.
|
| 715 |
+
allow_trailing_junk,
|
| 716 |
+
junk_string_value_,
|
| 717 |
+
read_as_double,
|
| 718 |
+
&result_is_junk);
|
| 719 |
+
DOUBLE_CONVERSION_ASSERT(!result_is_junk);
|
| 720 |
+
*processed_characters_count = static_cast<int>(current - input);
|
| 721 |
+
return result;
|
| 722 |
+
}
|
| 723 |
+
|
| 724 |
+
if (nonzero_digit_dropped) {
|
| 725 |
+
buffer[buffer_pos++] = '1';
|
| 726 |
+
exponent--;
|
| 727 |
+
}
|
| 728 |
+
|
| 729 |
+
DOUBLE_CONVERSION_ASSERT(buffer_pos < kBufferSize);
|
| 730 |
+
buffer[buffer_pos] = '\0';
|
| 731 |
+
|
| 732 |
+
// Code above ensures there are no leading zeros and the buffer has fewer than
|
| 733 |
+
// kMaxSignificantDecimalDigits characters. Trim trailing zeros.
|
| 734 |
+
Vector<const char> chars(buffer, buffer_pos);
|
| 735 |
+
chars = TrimTrailingZeros(chars);
|
| 736 |
+
exponent += buffer_pos - chars.length();
|
| 737 |
+
|
| 738 |
+
double converted;
|
| 739 |
+
if (read_as_double) {
|
| 740 |
+
converted = StrtodTrimmed(chars, exponent);
|
| 741 |
+
} else {
|
| 742 |
+
converted = StrtofTrimmed(chars, exponent);
|
| 743 |
+
}
|
| 744 |
+
*processed_characters_count = static_cast<int>(current - input);
|
| 745 |
+
return sign? -converted: converted;
|
| 746 |
+
}
|
| 747 |
+
|
| 748 |
+
|
| 749 |
+
double StringToDoubleConverter::StringToDouble(
|
| 750 |
+
const char* buffer,
|
| 751 |
+
int length,
|
| 752 |
+
int* processed_characters_count) const {
|
| 753 |
+
return StringToIeee(buffer, length, true, processed_characters_count);
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
|
| 757 |
+
double StringToDoubleConverter::StringToDouble(
|
| 758 |
+
const uc16* buffer,
|
| 759 |
+
int length,
|
| 760 |
+
int* processed_characters_count) const {
|
| 761 |
+
return StringToIeee(buffer, length, true, processed_characters_count);
|
| 762 |
+
}
|
| 763 |
+
|
| 764 |
+
|
| 765 |
+
float StringToDoubleConverter::StringToFloat(
|
| 766 |
+
const char* buffer,
|
| 767 |
+
int length,
|
| 768 |
+
int* processed_characters_count) const {
|
| 769 |
+
return static_cast<float>(StringToIeee(buffer, length, false,
|
| 770 |
+
processed_characters_count));
|
| 771 |
+
}
|
| 772 |
+
|
| 773 |
+
|
| 774 |
+
float StringToDoubleConverter::StringToFloat(
|
| 775 |
+
const uc16* buffer,
|
| 776 |
+
int length,
|
| 777 |
+
int* processed_characters_count) const {
|
| 778 |
+
return static_cast<float>(StringToIeee(buffer, length, false,
|
| 779 |
+
processed_characters_count));
|
| 780 |
+
}
|
| 781 |
+
|
| 782 |
+
|
| 783 |
+
template<>
|
| 784 |
+
double StringToDoubleConverter::StringTo<double>(
|
| 785 |
+
const char* buffer,
|
| 786 |
+
int length,
|
| 787 |
+
int* processed_characters_count) const {
|
| 788 |
+
return StringToDouble(buffer, length, processed_characters_count);
|
| 789 |
+
}
|
| 790 |
+
|
| 791 |
+
|
| 792 |
+
template<>
|
| 793 |
+
float StringToDoubleConverter::StringTo<float>(
|
| 794 |
+
const char* buffer,
|
| 795 |
+
int length,
|
| 796 |
+
int* processed_characters_count) const {
|
| 797 |
+
return StringToFloat(buffer, length, processed_characters_count);
|
| 798 |
+
}
|
| 799 |
+
|
| 800 |
+
|
| 801 |
+
template<>
|
| 802 |
+
double StringToDoubleConverter::StringTo<double>(
|
| 803 |
+
const uc16* buffer,
|
| 804 |
+
int length,
|
| 805 |
+
int* processed_characters_count) const {
|
| 806 |
+
return StringToDouble(buffer, length, processed_characters_count);
|
| 807 |
+
}
|
| 808 |
+
|
| 809 |
+
|
| 810 |
+
template<>
|
| 811 |
+
float StringToDoubleConverter::StringTo<float>(
|
| 812 |
+
const uc16* buffer,
|
| 813 |
+
int length,
|
| 814 |
+
int* processed_characters_count) const {
|
| 815 |
+
return StringToFloat(buffer, length, processed_characters_count);
|
| 816 |
+
}
|
| 817 |
+
|
| 818 |
+
} // namespace double_conversion
|
cpp-compiled/sources/double-conversion/string-to-double.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/strtod.cc
ADDED
|
@@ -0,0 +1,608 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2010 the V8 project authors. All rights reserved.
|
| 2 |
+
// Redistribution and use in source and binary forms, with or without
|
| 3 |
+
// modification, are permitted provided that the following conditions are
|
| 4 |
+
// met:
|
| 5 |
+
//
|
| 6 |
+
// * Redistributions of source code must retain the above copyright
|
| 7 |
+
// notice, this list of conditions and the following disclaimer.
|
| 8 |
+
// * Redistributions in binary form must reproduce the above
|
| 9 |
+
// copyright notice, this list of conditions and the following
|
| 10 |
+
// disclaimer in the documentation and/or other materials provided
|
| 11 |
+
// with the distribution.
|
| 12 |
+
// * Neither the name of Google Inc. nor the names of its
|
| 13 |
+
// contributors may be used to endorse or promote products derived
|
| 14 |
+
// from this software without specific prior written permission.
|
| 15 |
+
//
|
| 16 |
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 17 |
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 18 |
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 19 |
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 20 |
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 21 |
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 22 |
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 23 |
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 24 |
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 25 |
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 26 |
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 |
+
|
| 28 |
+
#include <climits>
|
| 29 |
+
#include <cstdarg>
|
| 30 |
+
|
| 31 |
+
#include "bignum.h"
|
| 32 |
+
#include "cached-powers.h"
|
| 33 |
+
#include "ieee.h"
|
| 34 |
+
#include "strtod.h"
|
| 35 |
+
|
| 36 |
+
namespace double_conversion {
|
| 37 |
+
|
| 38 |
+
#if defined(DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS)
|
| 39 |
+
// 2^53 = 9007199254740992.
|
| 40 |
+
// Any integer with at most 15 decimal digits will hence fit into a double
|
| 41 |
+
// (which has a 53bit significand) without loss of precision.
|
| 42 |
+
static const int kMaxExactDoubleIntegerDecimalDigits = 15;
|
| 43 |
+
#endif // #if defined(DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS)
|
| 44 |
+
// 2^64 = 18446744073709551616 > 10^19
|
| 45 |
+
static const int kMaxUint64DecimalDigits = 19;
|
| 46 |
+
|
| 47 |
+
// Max double: 1.7976931348623157 x 10^308
|
| 48 |
+
// Min non-zero double: 4.9406564584124654 x 10^-324
|
| 49 |
+
// Any x >= 10^309 is interpreted as +infinity.
|
| 50 |
+
// Any x <= 10^-324 is interpreted as 0.
|
| 51 |
+
// Note that 2.5e-324 (despite being smaller than the min double) will be read
|
| 52 |
+
// as non-zero (equal to the min non-zero double).
|
| 53 |
+
static const int kMaxDecimalPower = 309;
|
| 54 |
+
static const int kMinDecimalPower = -324;
|
| 55 |
+
|
| 56 |
+
// 2^64 = 18446744073709551616
|
| 57 |
+
static const uint64_t kMaxUint64 = DOUBLE_CONVERSION_UINT64_2PART_C(0xFFFFFFFF, FFFFFFFF);
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
#if defined(DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS)
|
| 61 |
+
static const double exact_powers_of_ten[] = {
|
| 62 |
+
1.0, // 10^0
|
| 63 |
+
10.0,
|
| 64 |
+
100.0,
|
| 65 |
+
1000.0,
|
| 66 |
+
10000.0,
|
| 67 |
+
100000.0,
|
| 68 |
+
1000000.0,
|
| 69 |
+
10000000.0,
|
| 70 |
+
100000000.0,
|
| 71 |
+
1000000000.0,
|
| 72 |
+
10000000000.0, // 10^10
|
| 73 |
+
100000000000.0,
|
| 74 |
+
1000000000000.0,
|
| 75 |
+
10000000000000.0,
|
| 76 |
+
100000000000000.0,
|
| 77 |
+
1000000000000000.0,
|
| 78 |
+
10000000000000000.0,
|
| 79 |
+
100000000000000000.0,
|
| 80 |
+
1000000000000000000.0,
|
| 81 |
+
10000000000000000000.0,
|
| 82 |
+
100000000000000000000.0, // 10^20
|
| 83 |
+
1000000000000000000000.0,
|
| 84 |
+
// 10^22 = 0x21e19e0c9bab2400000 = 0x878678326eac9 * 2^22
|
| 85 |
+
10000000000000000000000.0
|
| 86 |
+
};
|
| 87 |
+
static const int kExactPowersOfTenSize = DOUBLE_CONVERSION_ARRAY_SIZE(exact_powers_of_ten);
|
| 88 |
+
#endif // #if defined(DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS)
|
| 89 |
+
|
| 90 |
+
// Maximum number of significant digits in the decimal representation.
|
| 91 |
+
// In fact the value is 772 (see conversions.cc), but to give us some margin
|
| 92 |
+
// we round up to 780.
|
| 93 |
+
static const int kMaxSignificantDecimalDigits = 780;
|
| 94 |
+
|
| 95 |
+
static Vector<const char> TrimLeadingZeros(Vector<const char> buffer) {
|
| 96 |
+
for (int i = 0; i < buffer.length(); i++) {
|
| 97 |
+
if (buffer[i] != '0') {
|
| 98 |
+
return buffer.SubVector(i, buffer.length());
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
return Vector<const char>(buffer.start(), 0);
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
static void CutToMaxSignificantDigits(Vector<const char> buffer,
|
| 105 |
+
int exponent,
|
| 106 |
+
char* significant_buffer,
|
| 107 |
+
int* significant_exponent) {
|
| 108 |
+
for (int i = 0; i < kMaxSignificantDecimalDigits - 1; ++i) {
|
| 109 |
+
significant_buffer[i] = buffer[i];
|
| 110 |
+
}
|
| 111 |
+
// The input buffer has been trimmed. Therefore the last digit must be
|
| 112 |
+
// different from '0'.
|
| 113 |
+
DOUBLE_CONVERSION_ASSERT(buffer[buffer.length() - 1] != '0');
|
| 114 |
+
// Set the last digit to be non-zero. This is sufficient to guarantee
|
| 115 |
+
// correct rounding.
|
| 116 |
+
significant_buffer[kMaxSignificantDecimalDigits - 1] = '1';
|
| 117 |
+
*significant_exponent =
|
| 118 |
+
exponent + (buffer.length() - kMaxSignificantDecimalDigits);
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
// Trims the buffer and cuts it to at most kMaxSignificantDecimalDigits.
|
| 123 |
+
// If possible the input-buffer is reused, but if the buffer needs to be
|
| 124 |
+
// modified (due to cutting), then the input needs to be copied into the
|
| 125 |
+
// buffer_copy_space.
|
| 126 |
+
static void TrimAndCut(Vector<const char> buffer, int exponent,
|
| 127 |
+
char* buffer_copy_space, int space_size,
|
| 128 |
+
Vector<const char>* trimmed, int* updated_exponent) {
|
| 129 |
+
Vector<const char> left_trimmed = TrimLeadingZeros(buffer);
|
| 130 |
+
Vector<const char> right_trimmed = TrimTrailingZeros(left_trimmed);
|
| 131 |
+
exponent += left_trimmed.length() - right_trimmed.length();
|
| 132 |
+
if (right_trimmed.length() > kMaxSignificantDecimalDigits) {
|
| 133 |
+
(void) space_size; // Mark variable as used.
|
| 134 |
+
DOUBLE_CONVERSION_ASSERT(space_size >= kMaxSignificantDecimalDigits);
|
| 135 |
+
CutToMaxSignificantDigits(right_trimmed, exponent,
|
| 136 |
+
buffer_copy_space, updated_exponent);
|
| 137 |
+
*trimmed = Vector<const char>(buffer_copy_space,
|
| 138 |
+
kMaxSignificantDecimalDigits);
|
| 139 |
+
} else {
|
| 140 |
+
*trimmed = right_trimmed;
|
| 141 |
+
*updated_exponent = exponent;
|
| 142 |
+
}
|
| 143 |
+
}
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
// Reads digits from the buffer and converts them to a uint64.
|
| 147 |
+
// Reads in as many digits as fit into a uint64.
|
| 148 |
+
// When the string starts with "1844674407370955161" no further digit is read.
|
| 149 |
+
// Since 2^64 = 18446744073709551616 it would still be possible read another
|
| 150 |
+
// digit if it was less or equal than 6, but this would complicate the code.
|
| 151 |
+
static uint64_t ReadUint64(Vector<const char> buffer,
|
| 152 |
+
int* number_of_read_digits) {
|
| 153 |
+
uint64_t result = 0;
|
| 154 |
+
int i = 0;
|
| 155 |
+
while (i < buffer.length() && result <= (kMaxUint64 / 10 - 1)) {
|
| 156 |
+
int digit = buffer[i++] - '0';
|
| 157 |
+
DOUBLE_CONVERSION_ASSERT(0 <= digit && digit <= 9);
|
| 158 |
+
result = 10 * result + digit;
|
| 159 |
+
}
|
| 160 |
+
*number_of_read_digits = i;
|
| 161 |
+
return result;
|
| 162 |
+
}
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
// Reads a DiyFp from the buffer.
|
| 166 |
+
// The returned DiyFp is not necessarily normalized.
|
| 167 |
+
// If remaining_decimals is zero then the returned DiyFp is accurate.
|
| 168 |
+
// Otherwise it has been rounded and has error of at most 1/2 ulp.
|
| 169 |
+
static void ReadDiyFp(Vector<const char> buffer,
|
| 170 |
+
DiyFp* result,
|
| 171 |
+
int* remaining_decimals) {
|
| 172 |
+
int read_digits;
|
| 173 |
+
uint64_t significand = ReadUint64(buffer, &read_digits);
|
| 174 |
+
if (buffer.length() == read_digits) {
|
| 175 |
+
*result = DiyFp(significand, 0);
|
| 176 |
+
*remaining_decimals = 0;
|
| 177 |
+
} else {
|
| 178 |
+
// Round the significand.
|
| 179 |
+
if (buffer[read_digits] >= '5') {
|
| 180 |
+
significand++;
|
| 181 |
+
}
|
| 182 |
+
// Compute the binary exponent.
|
| 183 |
+
int exponent = 0;
|
| 184 |
+
*result = DiyFp(significand, exponent);
|
| 185 |
+
*remaining_decimals = buffer.length() - read_digits;
|
| 186 |
+
}
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
static bool DoubleStrtod(Vector<const char> trimmed,
|
| 191 |
+
int exponent,
|
| 192 |
+
double* result) {
|
| 193 |
+
#if !defined(DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS)
|
| 194 |
+
// Avoid "unused parameter" warnings
|
| 195 |
+
(void) trimmed;
|
| 196 |
+
(void) exponent;
|
| 197 |
+
(void) result;
|
| 198 |
+
// On x86 the floating-point stack can be 64 or 80 bits wide. If it is
|
| 199 |
+
// 80 bits wide (as is the case on Linux) then double-rounding occurs and the
|
| 200 |
+
// result is not accurate.
|
| 201 |
+
// We know that Windows32 uses 64 bits and is therefore accurate.
|
| 202 |
+
return false;
|
| 203 |
+
#else
|
| 204 |
+
if (trimmed.length() <= kMaxExactDoubleIntegerDecimalDigits) {
|
| 205 |
+
int read_digits;
|
| 206 |
+
// The trimmed input fits into a double.
|
| 207 |
+
// If the 10^exponent (resp. 10^-exponent) fits into a double too then we
|
| 208 |
+
// can compute the result-double simply by multiplying (resp. dividing) the
|
| 209 |
+
// two numbers.
|
| 210 |
+
// This is possible because IEEE guarantees that floating-point operations
|
| 211 |
+
// return the best possible approximation.
|
| 212 |
+
if (exponent < 0 && -exponent < kExactPowersOfTenSize) {
|
| 213 |
+
// 10^-exponent fits into a double.
|
| 214 |
+
*result = static_cast<double>(ReadUint64(trimmed, &read_digits));
|
| 215 |
+
DOUBLE_CONVERSION_ASSERT(read_digits == trimmed.length());
|
| 216 |
+
*result /= exact_powers_of_ten[-exponent];
|
| 217 |
+
return true;
|
| 218 |
+
}
|
| 219 |
+
if (0 <= exponent && exponent < kExactPowersOfTenSize) {
|
| 220 |
+
// 10^exponent fits into a double.
|
| 221 |
+
*result = static_cast<double>(ReadUint64(trimmed, &read_digits));
|
| 222 |
+
DOUBLE_CONVERSION_ASSERT(read_digits == trimmed.length());
|
| 223 |
+
*result *= exact_powers_of_ten[exponent];
|
| 224 |
+
return true;
|
| 225 |
+
}
|
| 226 |
+
int remaining_digits =
|
| 227 |
+
kMaxExactDoubleIntegerDecimalDigits - trimmed.length();
|
| 228 |
+
if ((0 <= exponent) &&
|
| 229 |
+
(exponent - remaining_digits < kExactPowersOfTenSize)) {
|
| 230 |
+
// The trimmed string was short and we can multiply it with
|
| 231 |
+
// 10^remaining_digits. As a result the remaining exponent now fits
|
| 232 |
+
// into a double too.
|
| 233 |
+
*result = static_cast<double>(ReadUint64(trimmed, &read_digits));
|
| 234 |
+
DOUBLE_CONVERSION_ASSERT(read_digits == trimmed.length());
|
| 235 |
+
*result *= exact_powers_of_ten[remaining_digits];
|
| 236 |
+
*result *= exact_powers_of_ten[exponent - remaining_digits];
|
| 237 |
+
return true;
|
| 238 |
+
}
|
| 239 |
+
}
|
| 240 |
+
return false;
|
| 241 |
+
#endif
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
// Returns 10^exponent as an exact DiyFp.
|
| 246 |
+
// The given exponent must be in the range [1; kDecimalExponentDistance[.
|
| 247 |
+
static DiyFp AdjustmentPowerOfTen(int exponent) {
|
| 248 |
+
DOUBLE_CONVERSION_ASSERT(0 < exponent);
|
| 249 |
+
DOUBLE_CONVERSION_ASSERT(exponent < PowersOfTenCache::kDecimalExponentDistance);
|
| 250 |
+
// Simply hardcode the remaining powers for the given decimal exponent
|
| 251 |
+
// distance.
|
| 252 |
+
DOUBLE_CONVERSION_ASSERT(PowersOfTenCache::kDecimalExponentDistance == 8);
|
| 253 |
+
switch (exponent) {
|
| 254 |
+
case 1: return DiyFp(DOUBLE_CONVERSION_UINT64_2PART_C(0xa0000000, 00000000), -60);
|
| 255 |
+
case 2: return DiyFp(DOUBLE_CONVERSION_UINT64_2PART_C(0xc8000000, 00000000), -57);
|
| 256 |
+
case 3: return DiyFp(DOUBLE_CONVERSION_UINT64_2PART_C(0xfa000000, 00000000), -54);
|
| 257 |
+
case 4: return DiyFp(DOUBLE_CONVERSION_UINT64_2PART_C(0x9c400000, 00000000), -50);
|
| 258 |
+
case 5: return DiyFp(DOUBLE_CONVERSION_UINT64_2PART_C(0xc3500000, 00000000), -47);
|
| 259 |
+
case 6: return DiyFp(DOUBLE_CONVERSION_UINT64_2PART_C(0xf4240000, 00000000), -44);
|
| 260 |
+
case 7: return DiyFp(DOUBLE_CONVERSION_UINT64_2PART_C(0x98968000, 00000000), -40);
|
| 261 |
+
default:
|
| 262 |
+
DOUBLE_CONVERSION_UNREACHABLE();
|
| 263 |
+
}
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
// If the function returns true then the result is the correct double.
|
| 268 |
+
// Otherwise it is either the correct double or the double that is just below
|
| 269 |
+
// the correct double.
|
| 270 |
+
static bool DiyFpStrtod(Vector<const char> buffer,
|
| 271 |
+
int exponent,
|
| 272 |
+
double* result) {
|
| 273 |
+
DiyFp input;
|
| 274 |
+
int remaining_decimals;
|
| 275 |
+
ReadDiyFp(buffer, &input, &remaining_decimals);
|
| 276 |
+
// Since we may have dropped some digits the input is not accurate.
|
| 277 |
+
// If remaining_decimals is different than 0 than the error is at most
|
| 278 |
+
// .5 ulp (unit in the last place).
|
| 279 |
+
// We don't want to deal with fractions and therefore keep a common
|
| 280 |
+
// denominator.
|
| 281 |
+
const int kDenominatorLog = 3;
|
| 282 |
+
const int kDenominator = 1 << kDenominatorLog;
|
| 283 |
+
// Move the remaining decimals into the exponent.
|
| 284 |
+
exponent += remaining_decimals;
|
| 285 |
+
uint64_t error = (remaining_decimals == 0 ? 0 : kDenominator / 2);
|
| 286 |
+
|
| 287 |
+
int old_e = input.e();
|
| 288 |
+
input.Normalize();
|
| 289 |
+
error <<= old_e - input.e();
|
| 290 |
+
|
| 291 |
+
DOUBLE_CONVERSION_ASSERT(exponent <= PowersOfTenCache::kMaxDecimalExponent);
|
| 292 |
+
if (exponent < PowersOfTenCache::kMinDecimalExponent) {
|
| 293 |
+
*result = 0.0;
|
| 294 |
+
return true;
|
| 295 |
+
}
|
| 296 |
+
DiyFp cached_power;
|
| 297 |
+
int cached_decimal_exponent;
|
| 298 |
+
PowersOfTenCache::GetCachedPowerForDecimalExponent(exponent,
|
| 299 |
+
&cached_power,
|
| 300 |
+
&cached_decimal_exponent);
|
| 301 |
+
|
| 302 |
+
if (cached_decimal_exponent != exponent) {
|
| 303 |
+
int adjustment_exponent = exponent - cached_decimal_exponent;
|
| 304 |
+
DiyFp adjustment_power = AdjustmentPowerOfTen(adjustment_exponent);
|
| 305 |
+
input.Multiply(adjustment_power);
|
| 306 |
+
if (kMaxUint64DecimalDigits - buffer.length() >= adjustment_exponent) {
|
| 307 |
+
// The product of input with the adjustment power fits into a 64 bit
|
| 308 |
+
// integer.
|
| 309 |
+
DOUBLE_CONVERSION_ASSERT(DiyFp::kSignificandSize == 64);
|
| 310 |
+
} else {
|
| 311 |
+
// The adjustment power is exact. There is hence only an error of 0.5.
|
| 312 |
+
error += kDenominator / 2;
|
| 313 |
+
}
|
| 314 |
+
}
|
| 315 |
+
|
| 316 |
+
input.Multiply(cached_power);
|
| 317 |
+
// The error introduced by a multiplication of a*b equals
|
| 318 |
+
// error_a + error_b + error_a*error_b/2^64 + 0.5
|
| 319 |
+
// Substituting a with 'input' and b with 'cached_power' we have
|
| 320 |
+
// error_b = 0.5 (all cached powers have an error of less than 0.5 ulp),
|
| 321 |
+
// error_ab = 0 or 1 / kDenominator > error_a*error_b/ 2^64
|
| 322 |
+
int error_b = kDenominator / 2;
|
| 323 |
+
int error_ab = (error == 0 ? 0 : 1); // We round up to 1.
|
| 324 |
+
int fixed_error = kDenominator / 2;
|
| 325 |
+
error += error_b + error_ab + fixed_error;
|
| 326 |
+
|
| 327 |
+
old_e = input.e();
|
| 328 |
+
input.Normalize();
|
| 329 |
+
error <<= old_e - input.e();
|
| 330 |
+
|
| 331 |
+
// See if the double's significand changes if we add/subtract the error.
|
| 332 |
+
int order_of_magnitude = DiyFp::kSignificandSize + input.e();
|
| 333 |
+
int effective_significand_size =
|
| 334 |
+
Double::SignificandSizeForOrderOfMagnitude(order_of_magnitude);
|
| 335 |
+
int precision_digits_count =
|
| 336 |
+
DiyFp::kSignificandSize - effective_significand_size;
|
| 337 |
+
if (precision_digits_count + kDenominatorLog >= DiyFp::kSignificandSize) {
|
| 338 |
+
// This can only happen for very small denormals. In this case the
|
| 339 |
+
// half-way multiplied by the denominator exceeds the range of an uint64.
|
| 340 |
+
// Simply shift everything to the right.
|
| 341 |
+
int shift_amount = (precision_digits_count + kDenominatorLog) -
|
| 342 |
+
DiyFp::kSignificandSize + 1;
|
| 343 |
+
input.set_f(input.f() >> shift_amount);
|
| 344 |
+
input.set_e(input.e() + shift_amount);
|
| 345 |
+
// We add 1 for the lost precision of error, and kDenominator for
|
| 346 |
+
// the lost precision of input.f().
|
| 347 |
+
error = (error >> shift_amount) + 1 + kDenominator;
|
| 348 |
+
precision_digits_count -= shift_amount;
|
| 349 |
+
}
|
| 350 |
+
// We use uint64_ts now. This only works if the DiyFp uses uint64_ts too.
|
| 351 |
+
DOUBLE_CONVERSION_ASSERT(DiyFp::kSignificandSize == 64);
|
| 352 |
+
DOUBLE_CONVERSION_ASSERT(precision_digits_count < 64);
|
| 353 |
+
uint64_t one64 = 1;
|
| 354 |
+
uint64_t precision_bits_mask = (one64 << precision_digits_count) - 1;
|
| 355 |
+
uint64_t precision_bits = input.f() & precision_bits_mask;
|
| 356 |
+
uint64_t half_way = one64 << (precision_digits_count - 1);
|
| 357 |
+
precision_bits *= kDenominator;
|
| 358 |
+
half_way *= kDenominator;
|
| 359 |
+
DiyFp rounded_input(input.f() >> precision_digits_count,
|
| 360 |
+
input.e() + precision_digits_count);
|
| 361 |
+
if (precision_bits >= half_way + error) {
|
| 362 |
+
rounded_input.set_f(rounded_input.f() + 1);
|
| 363 |
+
}
|
| 364 |
+
// If the last_bits are too close to the half-way case than we are too
|
| 365 |
+
// inaccurate and round down. In this case we return false so that we can
|
| 366 |
+
// fall back to a more precise algorithm.
|
| 367 |
+
|
| 368 |
+
*result = Double(rounded_input).value();
|
| 369 |
+
if (half_way - error < precision_bits && precision_bits < half_way + error) {
|
| 370 |
+
// Too imprecise. The caller will have to fall back to a slower version.
|
| 371 |
+
// However the returned number is guaranteed to be either the correct
|
| 372 |
+
// double, or the next-lower double.
|
| 373 |
+
return false;
|
| 374 |
+
} else {
|
| 375 |
+
return true;
|
| 376 |
+
}
|
| 377 |
+
}
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
// Returns
|
| 381 |
+
// - -1 if buffer*10^exponent < diy_fp.
|
| 382 |
+
// - 0 if buffer*10^exponent == diy_fp.
|
| 383 |
+
// - +1 if buffer*10^exponent > diy_fp.
|
| 384 |
+
// Preconditions:
|
| 385 |
+
// buffer.length() + exponent <= kMaxDecimalPower + 1
|
| 386 |
+
// buffer.length() + exponent > kMinDecimalPower
|
| 387 |
+
// buffer.length() <= kMaxDecimalSignificantDigits
|
| 388 |
+
static int CompareBufferWithDiyFp(Vector<const char> buffer,
|
| 389 |
+
int exponent,
|
| 390 |
+
DiyFp diy_fp) {
|
| 391 |
+
DOUBLE_CONVERSION_ASSERT(buffer.length() + exponent <= kMaxDecimalPower + 1);
|
| 392 |
+
DOUBLE_CONVERSION_ASSERT(buffer.length() + exponent > kMinDecimalPower);
|
| 393 |
+
DOUBLE_CONVERSION_ASSERT(buffer.length() <= kMaxSignificantDecimalDigits);
|
| 394 |
+
// Make sure that the Bignum will be able to hold all our numbers.
|
| 395 |
+
// Our Bignum implementation has a separate field for exponents. Shifts will
|
| 396 |
+
// consume at most one bigit (< 64 bits).
|
| 397 |
+
// ln(10) == 3.3219...
|
| 398 |
+
DOUBLE_CONVERSION_ASSERT(((kMaxDecimalPower + 1) * 333 / 100) < Bignum::kMaxSignificantBits);
|
| 399 |
+
Bignum buffer_bignum;
|
| 400 |
+
Bignum diy_fp_bignum;
|
| 401 |
+
buffer_bignum.AssignDecimalString(buffer);
|
| 402 |
+
diy_fp_bignum.AssignUInt64(diy_fp.f());
|
| 403 |
+
if (exponent >= 0) {
|
| 404 |
+
buffer_bignum.MultiplyByPowerOfTen(exponent);
|
| 405 |
+
} else {
|
| 406 |
+
diy_fp_bignum.MultiplyByPowerOfTen(-exponent);
|
| 407 |
+
}
|
| 408 |
+
if (diy_fp.e() > 0) {
|
| 409 |
+
diy_fp_bignum.ShiftLeft(diy_fp.e());
|
| 410 |
+
} else {
|
| 411 |
+
buffer_bignum.ShiftLeft(-diy_fp.e());
|
| 412 |
+
}
|
| 413 |
+
return Bignum::Compare(buffer_bignum, diy_fp_bignum);
|
| 414 |
+
}
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
// Returns true if the guess is the correct double.
|
| 418 |
+
// Returns false, when guess is either correct or the next-lower double.
|
| 419 |
+
static bool ComputeGuess(Vector<const char> trimmed, int exponent,
|
| 420 |
+
double* guess) {
|
| 421 |
+
if (trimmed.length() == 0) {
|
| 422 |
+
*guess = 0.0;
|
| 423 |
+
return true;
|
| 424 |
+
}
|
| 425 |
+
if (exponent + trimmed.length() - 1 >= kMaxDecimalPower) {
|
| 426 |
+
*guess = Double::Infinity();
|
| 427 |
+
return true;
|
| 428 |
+
}
|
| 429 |
+
if (exponent + trimmed.length() <= kMinDecimalPower) {
|
| 430 |
+
*guess = 0.0;
|
| 431 |
+
return true;
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
if (DoubleStrtod(trimmed, exponent, guess) ||
|
| 435 |
+
DiyFpStrtod(trimmed, exponent, guess)) {
|
| 436 |
+
return true;
|
| 437 |
+
}
|
| 438 |
+
if (*guess == Double::Infinity()) {
|
| 439 |
+
return true;
|
| 440 |
+
}
|
| 441 |
+
return false;
|
| 442 |
+
}
|
| 443 |
+
|
| 444 |
+
static bool IsDigit(const char d) {
|
| 445 |
+
return ('0' <= d) && (d <= '9');
|
| 446 |
+
}
|
| 447 |
+
|
| 448 |
+
static bool IsNonZeroDigit(const char d) {
|
| 449 |
+
return ('1' <= d) && (d <= '9');
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
#ifdef __has_cpp_attribute
|
| 453 |
+
#if __has_cpp_attribute(maybe_unused)
|
| 454 |
+
[[maybe_unused]]
|
| 455 |
+
#endif
|
| 456 |
+
#endif
|
| 457 |
+
static bool AssertTrimmedDigits(const Vector<const char>& buffer) {
|
| 458 |
+
for(int i = 0; i < buffer.length(); ++i) {
|
| 459 |
+
if(!IsDigit(buffer[i])) {
|
| 460 |
+
return false;
|
| 461 |
+
}
|
| 462 |
+
}
|
| 463 |
+
return (buffer.length() == 0) || (IsNonZeroDigit(buffer[0]) && IsNonZeroDigit(buffer[buffer.length()-1]));
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
double StrtodTrimmed(Vector<const char> trimmed, int exponent) {
|
| 467 |
+
DOUBLE_CONVERSION_ASSERT(trimmed.length() <= kMaxSignificantDecimalDigits);
|
| 468 |
+
DOUBLE_CONVERSION_ASSERT(AssertTrimmedDigits(trimmed));
|
| 469 |
+
double guess;
|
| 470 |
+
const bool is_correct = ComputeGuess(trimmed, exponent, &guess);
|
| 471 |
+
if (is_correct) {
|
| 472 |
+
return guess;
|
| 473 |
+
}
|
| 474 |
+
DiyFp upper_boundary = Double(guess).UpperBoundary();
|
| 475 |
+
int comparison = CompareBufferWithDiyFp(trimmed, exponent, upper_boundary);
|
| 476 |
+
if (comparison < 0) {
|
| 477 |
+
return guess;
|
| 478 |
+
} else if (comparison > 0) {
|
| 479 |
+
return Double(guess).NextDouble();
|
| 480 |
+
} else if ((Double(guess).Significand() & 1) == 0) {
|
| 481 |
+
// Round towards even.
|
| 482 |
+
return guess;
|
| 483 |
+
} else {
|
| 484 |
+
return Double(guess).NextDouble();
|
| 485 |
+
}
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
double Strtod(Vector<const char> buffer, int exponent) {
|
| 489 |
+
char copy_buffer[kMaxSignificantDecimalDigits];
|
| 490 |
+
Vector<const char> trimmed;
|
| 491 |
+
int updated_exponent;
|
| 492 |
+
TrimAndCut(buffer, exponent, copy_buffer, kMaxSignificantDecimalDigits,
|
| 493 |
+
&trimmed, &updated_exponent);
|
| 494 |
+
return StrtodTrimmed(trimmed, updated_exponent);
|
| 495 |
+
}
|
| 496 |
+
|
| 497 |
+
static float SanitizedDoubletof(double d) {
|
| 498 |
+
DOUBLE_CONVERSION_ASSERT(d >= 0.0);
|
| 499 |
+
// ASAN has a sanitize check that disallows casting doubles to floats if
|
| 500 |
+
// they are too big.
|
| 501 |
+
// https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#available-checks
|
| 502 |
+
// The behavior should be covered by IEEE 754, but some projects use this
|
| 503 |
+
// flag, so work around it.
|
| 504 |
+
float max_finite = 3.4028234663852885981170418348451692544e+38;
|
| 505 |
+
// The half-way point between the max-finite and infinity value.
|
| 506 |
+
// Since infinity has an even significand everything equal or greater than
|
| 507 |
+
// this value should become infinity.
|
| 508 |
+
double half_max_finite_infinity =
|
| 509 |
+
3.40282356779733661637539395458142568448e+38;
|
| 510 |
+
if (d >= max_finite) {
|
| 511 |
+
if (d >= half_max_finite_infinity) {
|
| 512 |
+
return Single::Infinity();
|
| 513 |
+
} else {
|
| 514 |
+
return max_finite;
|
| 515 |
+
}
|
| 516 |
+
} else {
|
| 517 |
+
return static_cast<float>(d);
|
| 518 |
+
}
|
| 519 |
+
}
|
| 520 |
+
|
| 521 |
+
float Strtof(Vector<const char> buffer, int exponent) {
|
| 522 |
+
char copy_buffer[kMaxSignificantDecimalDigits];
|
| 523 |
+
Vector<const char> trimmed;
|
| 524 |
+
int updated_exponent;
|
| 525 |
+
TrimAndCut(buffer, exponent, copy_buffer, kMaxSignificantDecimalDigits,
|
| 526 |
+
&trimmed, &updated_exponent);
|
| 527 |
+
exponent = updated_exponent;
|
| 528 |
+
return StrtofTrimmed(trimmed, exponent);
|
| 529 |
+
}
|
| 530 |
+
|
| 531 |
+
float StrtofTrimmed(Vector<const char> trimmed, int exponent) {
|
| 532 |
+
DOUBLE_CONVERSION_ASSERT(trimmed.length() <= kMaxSignificantDecimalDigits);
|
| 533 |
+
DOUBLE_CONVERSION_ASSERT(AssertTrimmedDigits(trimmed));
|
| 534 |
+
|
| 535 |
+
double double_guess;
|
| 536 |
+
bool is_correct = ComputeGuess(trimmed, exponent, &double_guess);
|
| 537 |
+
|
| 538 |
+
float float_guess = SanitizedDoubletof(double_guess);
|
| 539 |
+
if (float_guess == double_guess) {
|
| 540 |
+
// This shortcut triggers for integer values.
|
| 541 |
+
return float_guess;
|
| 542 |
+
}
|
| 543 |
+
|
| 544 |
+
// We must catch double-rounding. Say the double has been rounded up, and is
|
| 545 |
+
// now a boundary of a float, and rounds up again. This is why we have to
|
| 546 |
+
// look at previous too.
|
| 547 |
+
// Example (in decimal numbers):
|
| 548 |
+
// input: 12349
|
| 549 |
+
// high-precision (4 digits): 1235
|
| 550 |
+
// low-precision (3 digits):
|
| 551 |
+
// when read from input: 123
|
| 552 |
+
// when rounded from high precision: 124.
|
| 553 |
+
// To do this we simply look at the neighbors of the correct result and see
|
| 554 |
+
// if they would round to the same float. If the guess is not correct we have
|
| 555 |
+
// to look at four values (since two different doubles could be the correct
|
| 556 |
+
// double).
|
| 557 |
+
|
| 558 |
+
double double_next = Double(double_guess).NextDouble();
|
| 559 |
+
double double_previous = Double(double_guess).PreviousDouble();
|
| 560 |
+
|
| 561 |
+
float f1 = SanitizedDoubletof(double_previous);
|
| 562 |
+
float f2 = float_guess;
|
| 563 |
+
float f3 = SanitizedDoubletof(double_next);
|
| 564 |
+
float f4;
|
| 565 |
+
if (is_correct) {
|
| 566 |
+
f4 = f3;
|
| 567 |
+
} else {
|
| 568 |
+
double double_next2 = Double(double_next).NextDouble();
|
| 569 |
+
f4 = SanitizedDoubletof(double_next2);
|
| 570 |
+
}
|
| 571 |
+
(void) f2; // Mark variable as used.
|
| 572 |
+
DOUBLE_CONVERSION_ASSERT(f1 <= f2 && f2 <= f3 && f3 <= f4);
|
| 573 |
+
|
| 574 |
+
// If the guess doesn't lie near a single-precision boundary we can simply
|
| 575 |
+
// return its float-value.
|
| 576 |
+
if (f1 == f4) {
|
| 577 |
+
return float_guess;
|
| 578 |
+
}
|
| 579 |
+
|
| 580 |
+
DOUBLE_CONVERSION_ASSERT((f1 != f2 && f2 == f3 && f3 == f4) ||
|
| 581 |
+
(f1 == f2 && f2 != f3 && f3 == f4) ||
|
| 582 |
+
(f1 == f2 && f2 == f3 && f3 != f4));
|
| 583 |
+
|
| 584 |
+
// guess and next are the two possible candidates (in the same way that
|
| 585 |
+
// double_guess was the lower candidate for a double-precision guess).
|
| 586 |
+
float guess = f1;
|
| 587 |
+
float next = f4;
|
| 588 |
+
DiyFp upper_boundary;
|
| 589 |
+
if (guess == 0.0f) {
|
| 590 |
+
float min_float = 1e-45f;
|
| 591 |
+
upper_boundary = Double(static_cast<double>(min_float) / 2).AsDiyFp();
|
| 592 |
+
} else {
|
| 593 |
+
upper_boundary = Single(guess).UpperBoundary();
|
| 594 |
+
}
|
| 595 |
+
int comparison = CompareBufferWithDiyFp(trimmed, exponent, upper_boundary);
|
| 596 |
+
if (comparison < 0) {
|
| 597 |
+
return guess;
|
| 598 |
+
} else if (comparison > 0) {
|
| 599 |
+
return next;
|
| 600 |
+
} else if ((Single(guess).Significand() & 1) == 0) {
|
| 601 |
+
// Round towards even.
|
| 602 |
+
return guess;
|
| 603 |
+
} else {
|
| 604 |
+
return next;
|
| 605 |
+
}
|
| 606 |
+
}
|
| 607 |
+
|
| 608 |
+
} // namespace double_conversion
|
cpp-compiled/sources/double-conversion/strtod.cc.ii
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
cpp-compiled/sources/double-conversion/test-bignum-dtoa.cc
ADDED
|
@@ -0,0 +1,400 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2012 the V8 project authors. All rights reserved.
|
| 2 |
+
// Redistribution and use in source and binary forms, with or without
|
| 3 |
+
// modification, are permitted provided that the following conditions are
|
| 4 |
+
// met:
|
| 5 |
+
//
|
| 6 |
+
// * Redistributions of source code must retain the above copyright
|
| 7 |
+
// notice, this list of conditions and the following disclaimer.
|
| 8 |
+
// * Redistributions in binary form must reproduce the above
|
| 9 |
+
// copyright notice, this list of conditions and the following
|
| 10 |
+
// disclaimer in the documentation and/or other materials provided
|
| 11 |
+
// with the distribution.
|
| 12 |
+
// * Neither the name of Google Inc. nor the names of its
|
| 13 |
+
// contributors may be used to endorse or promote products derived
|
| 14 |
+
// from this software without specific prior written permission.
|
| 15 |
+
//
|
| 16 |
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 17 |
+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 18 |
+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 19 |
+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 20 |
+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 21 |
+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 22 |
+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 23 |
+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 24 |
+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 25 |
+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 26 |
+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 27 |
+
|
| 28 |
+
#include <stdlib.h>
|
| 29 |
+
|
| 30 |
+
#include "double-conversion/bignum-dtoa.h"
|
| 31 |
+
|
| 32 |
+
#include "cctest.h"
|
| 33 |
+
#include "gay-fixed.h"
|
| 34 |
+
#include "gay-precision.h"
|
| 35 |
+
#include "gay-shortest.h"
|
| 36 |
+
#include "gay-shortest-single.h"
|
| 37 |
+
#include "double-conversion/ieee.h"
|
| 38 |
+
#include "double-conversion/utils.h"
|
| 39 |
+
|
| 40 |
+
using namespace double_conversion;
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
// Removes trailing '0' digits.
|
| 44 |
+
// Can return the empty string if all digits are 0.
|
| 45 |
+
static void TrimRepresentation(Vector<char> representation) {
|
| 46 |
+
int len = static_cast<int>(strlen(representation.start()));
|
| 47 |
+
int i;
|
| 48 |
+
for (i = len - 1; i >= 0; --i) {
|
| 49 |
+
if (representation[i] != '0') break;
|
| 50 |
+
}
|
| 51 |
+
representation[i + 1] = '\0';
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
static const int kBufferSize = 100;
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
TEST(BignumDtoaVariousDoubles) {
|
| 59 |
+
char buffer_container[kBufferSize];
|
| 60 |
+
Vector<char> buffer(buffer_container, kBufferSize);
|
| 61 |
+
int length;
|
| 62 |
+
int point;
|
| 63 |
+
|
| 64 |
+
BignumDtoa(1.0, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
|
| 65 |
+
CHECK_EQ("1", buffer.start());
|
| 66 |
+
CHECK_EQ(1, point);
|
| 67 |
+
|
| 68 |
+
BignumDtoa(1.0, BIGNUM_DTOA_FIXED, 3, buffer, &length, &point);
|
| 69 |
+
CHECK_GE(3, length - point);
|
| 70 |
+
TrimRepresentation(buffer);
|
| 71 |
+
CHECK_EQ("1", buffer.start());
|
| 72 |
+
CHECK_EQ(1, point);
|
| 73 |
+
|
| 74 |
+
BignumDtoa(1.0, BIGNUM_DTOA_PRECISION, 3, buffer, &length, &point);
|
| 75 |
+
CHECK_GE(3, length);
|
| 76 |
+
TrimRepresentation(buffer);
|
| 77 |
+
CHECK_EQ("1", buffer.start());
|
| 78 |
+
CHECK_EQ(1, point);
|
| 79 |
+
|
| 80 |
+
BignumDtoa(1.5, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
|
| 81 |
+
CHECK_EQ("15", buffer.start());
|
| 82 |
+
CHECK_EQ(1, point);
|
| 83 |
+
|
| 84 |
+
BignumDtoa(1.5, BIGNUM_DTOA_FIXED, 10, buffer, &length, &point);
|
| 85 |
+
CHECK_GE(10, length - point);
|
| 86 |
+
TrimRepresentation(buffer);
|
| 87 |
+
CHECK_EQ("15", buffer.start());
|
| 88 |
+
CHECK_EQ(1, point);
|
| 89 |
+
|
| 90 |
+
BignumDtoa(1.5, BIGNUM_DTOA_PRECISION, 10, buffer, &length, &point);
|
| 91 |
+
CHECK_GE(10, length);
|
| 92 |
+
TrimRepresentation(buffer);
|
| 93 |
+
CHECK_EQ("15", buffer.start());
|
| 94 |
+
CHECK_EQ(1, point);
|
| 95 |
+
|
| 96 |
+
double min_double = 5e-324;
|
| 97 |
+
BignumDtoa(min_double, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
|
| 98 |
+
CHECK_EQ("5", buffer.start());
|
| 99 |
+
CHECK_EQ(-323, point);
|
| 100 |
+
|
| 101 |
+
BignumDtoa(min_double, BIGNUM_DTOA_FIXED, 5, buffer, &length, &point);
|
| 102 |
+
CHECK_GE(5, length - point);
|
| 103 |
+
TrimRepresentation(buffer);
|
| 104 |
+
CHECK_EQ("", buffer.start());
|
| 105 |
+
|
| 106 |
+
BignumDtoa(min_double, BIGNUM_DTOA_PRECISION, 5, buffer, &length, &point);
|
| 107 |
+
CHECK_GE(5, length);
|
| 108 |
+
TrimRepresentation(buffer);
|
| 109 |
+
CHECK_EQ("49407", buffer.start());
|
| 110 |
+
CHECK_EQ(-323, point);
|
| 111 |
+
|
| 112 |
+
double max_double = 1.7976931348623157e308;
|
| 113 |
+
BignumDtoa(max_double, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
|
| 114 |
+
CHECK_EQ("17976931348623157", buffer.start());
|
| 115 |
+
CHECK_EQ(309, point);
|
| 116 |
+
|
| 117 |
+
BignumDtoa(max_double, BIGNUM_DTOA_PRECISION, 7, buffer, &length, &point);
|
| 118 |
+
CHECK_GE(7, length);
|
| 119 |
+
TrimRepresentation(buffer);
|
| 120 |
+
CHECK_EQ("1797693", buffer.start());
|
| 121 |
+
CHECK_EQ(309, point);
|
| 122 |
+
|
| 123 |
+
BignumDtoa(4294967272.0, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
|
| 124 |
+
CHECK_EQ("4294967272", buffer.start());
|
| 125 |
+
CHECK_EQ(10, point);
|
| 126 |
+
|
| 127 |
+
BignumDtoa(4294967272.0, BIGNUM_DTOA_FIXED, 5, buffer, &length, &point);
|
| 128 |
+
CHECK_EQ("429496727200000", buffer.start());
|
| 129 |
+
CHECK_EQ(10, point);
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
BignumDtoa(4294967272.0, BIGNUM_DTOA_PRECISION, 14, buffer, &length, &point);
|
| 133 |
+
CHECK_GE(14, length);
|
| 134 |
+
TrimRepresentation(buffer);
|
| 135 |
+
CHECK_EQ("4294967272", buffer.start());
|
| 136 |
+
CHECK_EQ(10, point);
|
| 137 |
+
|
| 138 |
+
BignumDtoa(4.1855804968213567e298, BIGNUM_DTOA_SHORTEST, 0,
|
| 139 |
+
buffer, &length, &point);
|
| 140 |
+
CHECK_EQ("4185580496821357", buffer.start());
|
| 141 |
+
CHECK_EQ(299, point);
|
| 142 |
+
|
| 143 |
+
BignumDtoa(4.1855804968213567e298, BIGNUM_DTOA_PRECISION, 20,
|
| 144 |
+
buffer, &length, &point);
|
| 145 |
+
CHECK_GE(20, length);
|
| 146 |
+
TrimRepresentation(buffer);
|
| 147 |
+
CHECK_EQ("41855804968213567225", buffer.start());
|
| 148 |
+
CHECK_EQ(299, point);
|
| 149 |
+
|
| 150 |
+
BignumDtoa(5.5626846462680035e-309, BIGNUM_DTOA_SHORTEST, 0,
|
| 151 |
+
buffer, &length, &point);
|
| 152 |
+
CHECK_EQ("5562684646268003", buffer.start());
|
| 153 |
+
CHECK_EQ(-308, point);
|
| 154 |
+
|
| 155 |
+
BignumDtoa(5.5626846462680035e-309, BIGNUM_DTOA_PRECISION, 1,
|
| 156 |
+
buffer, &length, &point);
|
| 157 |
+
CHECK_GE(1, length);
|
| 158 |
+
TrimRepresentation(buffer);
|
| 159 |
+
CHECK_EQ("6", buffer.start());
|
| 160 |
+
CHECK_EQ(-308, point);
|
| 161 |
+
|
| 162 |
+
BignumDtoa(2147483648.0, BIGNUM_DTOA_SHORTEST, 0,
|
| 163 |
+
buffer, &length, &point);
|
| 164 |
+
CHECK_EQ("2147483648", buffer.start());
|
| 165 |
+
CHECK_EQ(10, point);
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
BignumDtoa(2147483648.0, BIGNUM_DTOA_FIXED, 2,
|
| 169 |
+
buffer, &length, &point);
|
| 170 |
+
CHECK_GE(2, length - point);
|
| 171 |
+
TrimRepresentation(buffer);
|
| 172 |
+
CHECK_EQ("2147483648", buffer.start());
|
| 173 |
+
CHECK_EQ(10, point);
|
| 174 |
+
|
| 175 |
+
BignumDtoa(2147483648.0, BIGNUM_DTOA_PRECISION, 5,
|
| 176 |
+
buffer, &length, &point);
|
| 177 |
+
CHECK_GE(5, length);
|
| 178 |
+
TrimRepresentation(buffer);
|
| 179 |
+
CHECK_EQ("21475", buffer.start());
|
| 180 |
+
CHECK_EQ(10, point);
|
| 181 |
+
|
| 182 |
+
BignumDtoa(3.5844466002796428e+298, BIGNUM_DTOA_SHORTEST, 0,
|
| 183 |
+
buffer, &length, &point);
|
| 184 |
+
CHECK_EQ("35844466002796428", buffer.start());
|
| 185 |
+
CHECK_EQ(299, point);
|
| 186 |
+
|
| 187 |
+
BignumDtoa(3.5844466002796428e+298, BIGNUM_DTOA_PRECISION, 10,
|
| 188 |
+
buffer, &length, &point);
|
| 189 |
+
CHECK_GE(10, length);
|
| 190 |
+
TrimRepresentation(buffer);
|
| 191 |
+
CHECK_EQ("35844466", buffer.start());
|
| 192 |
+
CHECK_EQ(299, point);
|
| 193 |
+
|
| 194 |
+
BignumDtoa(1e-23, BIGNUM_DTOA_SHORTEST, 0,
|
| 195 |
+
buffer, &length, &point);
|
| 196 |
+
CHECK_EQ("1", buffer.start());
|
| 197 |
+
CHECK_EQ(-22, point);
|
| 198 |
+
|
| 199 |
+
uint64_t smallest_normal64 = DOUBLE_CONVERSION_UINT64_2PART_C(0x00100000, 00000000);
|
| 200 |
+
double v = Double(smallest_normal64).value();
|
| 201 |
+
BignumDtoa(v, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
|
| 202 |
+
CHECK_EQ("22250738585072014", buffer.start());
|
| 203 |
+
CHECK_EQ(-307, point);
|
| 204 |
+
|
| 205 |
+
BignumDtoa(v, BIGNUM_DTOA_PRECISION, 20, buffer, &length, &point);
|
| 206 |
+
CHECK_GE(20, length);
|
| 207 |
+
TrimRepresentation(buffer);
|
| 208 |
+
CHECK_EQ("22250738585072013831", buffer.start());
|
| 209 |
+
CHECK_EQ(-307, point);
|
| 210 |
+
|
| 211 |
+
uint64_t largest_denormal64 = DOUBLE_CONVERSION_UINT64_2PART_C(0x000FFFFF, FFFFFFFF);
|
| 212 |
+
v = Double(largest_denormal64).value();
|
| 213 |
+
BignumDtoa(v, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
|
| 214 |
+
CHECK_EQ("2225073858507201", buffer.start());
|
| 215 |
+
CHECK_EQ(-307, point);
|
| 216 |
+
|
| 217 |
+
BignumDtoa(v, BIGNUM_DTOA_PRECISION, 20, buffer, &length, &point);
|
| 218 |
+
CHECK_GE(20, length);
|
| 219 |
+
TrimRepresentation(buffer);
|
| 220 |
+
CHECK_EQ("2225073858507200889", buffer.start());
|
| 221 |
+
CHECK_EQ(-307, point);
|
| 222 |
+
|
| 223 |
+
BignumDtoa(4128420500802942e-24, BIGNUM_DTOA_SHORTEST, 0,
|
| 224 |
+
buffer, &length, &point);
|
| 225 |
+
CHECK_EQ("4128420500802942", buffer.start());
|
| 226 |
+
CHECK_EQ(-8, point);
|
| 227 |
+
|
| 228 |
+
v = 3.9292015898194142585311918e-10;
|
| 229 |
+
BignumDtoa(v, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
|
| 230 |
+
CHECK_EQ("39292015898194143", buffer.start());
|
| 231 |
+
|
| 232 |
+
v = 4194304.0;
|
| 233 |
+
BignumDtoa(v, BIGNUM_DTOA_FIXED, 5, buffer, &length, &point);
|
| 234 |
+
CHECK_GE(5, length - point);
|
| 235 |
+
TrimRepresentation(buffer);
|
| 236 |
+
CHECK_EQ("4194304", buffer.start());
|
| 237 |
+
|
| 238 |
+
v = 3.3161339052167390562200598e-237;
|
| 239 |
+
BignumDtoa(v, BIGNUM_DTOA_PRECISION, 19, buffer, &length, &point);
|
| 240 |
+
CHECK_GE(19, length);
|
| 241 |
+
TrimRepresentation(buffer);
|
| 242 |
+
CHECK_EQ("3316133905216739056", buffer.start());
|
| 243 |
+
CHECK_EQ(-236, point);
|
| 244 |
+
|
| 245 |
+
v = 7.9885183916008099497815232e+191;
|
| 246 |
+
BignumDtoa(v, BIGNUM_DTOA_PRECISION, 4, buffer, &length, &point);
|
| 247 |
+
CHECK_GE(4, length);
|
| 248 |
+
TrimRepresentation(buffer);
|
| 249 |
+
CHECK_EQ("7989", buffer.start());
|
| 250 |
+
CHECK_EQ(192, point);
|
| 251 |
+
|
| 252 |
+
v = 1.0000000000000012800000000e+17;
|
| 253 |
+
BignumDtoa(v, BIGNUM_DTOA_FIXED, 1, buffer, &length, &point);
|
| 254 |
+
CHECK_GE(1, length - point);
|
| 255 |
+
TrimRepresentation(buffer);
|
| 256 |
+
CHECK_EQ("100000000000000128", buffer.start());
|
| 257 |
+
CHECK_EQ(18, point);
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
TEST(BignumDtoaShortestVariousFloats) {
|
| 262 |
+
char buffer_container[kBufferSize];
|
| 263 |
+
Vector<char> buffer(buffer_container, kBufferSize);
|
| 264 |
+
int length;
|
| 265 |
+
int point;
|
| 266 |
+
|
| 267 |
+
float min_float = 1e-45f;
|
| 268 |
+
BignumDtoa(min_float, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
|
| 269 |
+
buffer, &length, &point);
|
| 270 |
+
CHECK_EQ("1", buffer.start());
|
| 271 |
+
CHECK_EQ(-44, point);
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
float max_float = 3.4028234e38f;
|
| 275 |
+
BignumDtoa(max_float, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
|
| 276 |
+
buffer, &length, &point);
|
| 277 |
+
CHECK_EQ("34028235", buffer.start());
|
| 278 |
+
CHECK_EQ(39, point);
|
| 279 |
+
|
| 280 |
+
BignumDtoa(4294967272.0f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
|
| 281 |
+
buffer, &length, &point);
|
| 282 |
+
CHECK_EQ("42949673", buffer.start());
|
| 283 |
+
CHECK_EQ(10, point);
|
| 284 |
+
|
| 285 |
+
BignumDtoa(3.32306998946228968226e+35f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
|
| 286 |
+
buffer, &length, &point);
|
| 287 |
+
CHECK_EQ("332307", buffer.start());
|
| 288 |
+
CHECK_EQ(36, point);
|
| 289 |
+
|
| 290 |
+
BignumDtoa(1.2341e-41f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
|
| 291 |
+
buffer, &length, &point);
|
| 292 |
+
CHECK_EQ("12341", buffer.start());
|
| 293 |
+
CHECK_EQ(-40, point);
|
| 294 |
+
|
| 295 |
+
BignumDtoa(3.3554432e7, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
|
| 296 |
+
buffer, &length, &point);
|
| 297 |
+
CHECK_EQ("33554432", buffer.start());
|
| 298 |
+
CHECK_EQ(8, point);
|
| 299 |
+
|
| 300 |
+
BignumDtoa(3.26494756798464e14f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
|
| 301 |
+
buffer, &length, &point);
|
| 302 |
+
CHECK_EQ("32649476", buffer.start());
|
| 303 |
+
CHECK_EQ(15, point);
|
| 304 |
+
|
| 305 |
+
BignumDtoa(3.91132223637771935344e37f, BIGNUM_DTOA_SHORTEST_SINGLE, 0,
|
| 306 |
+
buffer, &length, &point);
|
| 307 |
+
CHECK_EQ("39113222", buffer.start());
|
| 308 |
+
CHECK_EQ(38, point);
|
| 309 |
+
|
| 310 |
+
uint32_t smallest_normal32 = 0x00800000;
|
| 311 |
+
double v = Single(smallest_normal32).value();
|
| 312 |
+
BignumDtoa(v, BIGNUM_DTOA_SHORTEST_SINGLE, 0, buffer, &length, &point);
|
| 313 |
+
CHECK_EQ("11754944", buffer.start());
|
| 314 |
+
CHECK_EQ(-37, point);
|
| 315 |
+
|
| 316 |
+
uint32_t largest_denormal32 = 0x007FFFFF;
|
| 317 |
+
v = Single(largest_denormal32).value();
|
| 318 |
+
BignumDtoa(v, BIGNUM_DTOA_SHORTEST_SINGLE, 0, buffer, &length, &point);
|
| 319 |
+
CHECK_EQ("11754942", buffer.start());
|
| 320 |
+
CHECK_EQ(-37, point);
|
| 321 |
+
}
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
TEST(BignumDtoaGayShortest) {
|
| 325 |
+
char buffer_container[kBufferSize];
|
| 326 |
+
Vector<char> buffer(buffer_container, kBufferSize);
|
| 327 |
+
int length;
|
| 328 |
+
int point;
|
| 329 |
+
|
| 330 |
+
Vector<const PrecomputedShortest> precomputed =
|
| 331 |
+
PrecomputedShortestRepresentations();
|
| 332 |
+
for (int i = 0; i < precomputed.length(); ++i) {
|
| 333 |
+
const PrecomputedShortest current_test = precomputed[i];
|
| 334 |
+
double v = current_test.v;
|
| 335 |
+
BignumDtoa(v, BIGNUM_DTOA_SHORTEST, 0, buffer, &length, &point);
|
| 336 |
+
CHECK_EQ(current_test.decimal_point, point);
|
| 337 |
+
CHECK_EQ(current_test.representation, buffer.start());
|
| 338 |
+
}
|
| 339 |
+
}
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
TEST(BignumDtoaGayShortestSingle) {
|
| 343 |
+
char buffer_container[kBufferSize];
|
| 344 |
+
Vector<char> buffer(buffer_container, kBufferSize);
|
| 345 |
+
int length;
|
| 346 |
+
int point;
|
| 347 |
+
|
| 348 |
+
Vector<const PrecomputedShortestSingle> precomputed =
|
| 349 |
+
PrecomputedShortestSingleRepresentations();
|
| 350 |
+
for (int i = 0; i < precomputed.length(); ++i) {
|
| 351 |
+
const PrecomputedShortestSingle current_test = precomputed[i];
|
| 352 |
+
float v = current_test.v;
|
| 353 |
+
BignumDtoa(v, BIGNUM_DTOA_SHORTEST_SINGLE, 0, buffer, &length, &point);
|
| 354 |
+
CHECK_EQ(current_test.decimal_point, point);
|
| 355 |
+
CHECK_EQ(current_test.representation, buffer.start());
|
| 356 |
+
}
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
TEST(BignumDtoaGayFixed) {
|
| 361 |
+
char buffer_container[kBufferSize];
|
| 362 |
+
Vector<char> buffer(buffer_container, kBufferSize);
|
| 363 |
+
int length;
|
| 364 |
+
int point;
|
| 365 |
+
|
| 366 |
+
Vector<const PrecomputedFixed> precomputed =
|
| 367 |
+
PrecomputedFixedRepresentations();
|
| 368 |
+
for (int i = 0; i < precomputed.length(); ++i) {
|
| 369 |
+
const PrecomputedFixed current_test = precomputed[i];
|
| 370 |
+
double v = current_test.v;
|
| 371 |
+
int number_digits = current_test.number_digits;
|
| 372 |
+
BignumDtoa(v, BIGNUM_DTOA_FIXED, number_digits, buffer, &length, &point);
|
| 373 |
+
CHECK_EQ(current_test.decimal_point, point);
|
| 374 |
+
CHECK_GE(number_digits, length - point);
|
| 375 |
+
TrimRepresentation(buffer);
|
| 376 |
+
CHECK_EQ(current_test.representation, buffer.start());
|
| 377 |
+
}
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
TEST(BignumDtoaGayPrecision) {
|
| 382 |
+
char buffer_container[kBufferSize];
|
| 383 |
+
Vector<char> buffer(buffer_container, kBufferSize);
|
| 384 |
+
int length;
|
| 385 |
+
int point;
|
| 386 |
+
|
| 387 |
+
Vector<const PrecomputedPrecision> precomputed =
|
| 388 |
+
PrecomputedPrecisionRepresentations();
|
| 389 |
+
for (int i = 0; i < precomputed.length(); ++i) {
|
| 390 |
+
const PrecomputedPrecision current_test = precomputed[i];
|
| 391 |
+
double v = current_test.v;
|
| 392 |
+
int number_digits = current_test.number_digits;
|
| 393 |
+
BignumDtoa(v, BIGNUM_DTOA_PRECISION, number_digits,
|
| 394 |
+
buffer, &length, &point);
|
| 395 |
+
CHECK_EQ(current_test.decimal_point, point);
|
| 396 |
+
CHECK_GE(number_digits, length);
|
| 397 |
+
TrimRepresentation(buffer);
|
| 398 |
+
CHECK_EQ(current_test.representation, buffer.start());
|
| 399 |
+
}
|
| 400 |
+
}
|