koffi 2.3.6-beta.6 → 2.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (276) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/package.json +2 -2
  3. package/src/cnoke/cnoke.js +3 -7
  4. package/src/cnoke/src/builder.js +9 -6
  5. package/src/cnoke/src/index.js +2 -2
  6. package/src/koffi/build/2.3.7/koffi_darwin_arm64/koffi.node +0 -0
  7. package/src/koffi/build/2.3.7/koffi_darwin_x64/koffi.node +0 -0
  8. package/src/koffi/build/2.3.7/koffi_freebsd_arm64/koffi.node +0 -0
  9. package/src/koffi/build/2.3.7/koffi_freebsd_ia32/koffi.node +0 -0
  10. package/src/koffi/build/2.3.7/koffi_freebsd_x64/koffi.node +0 -0
  11. package/src/koffi/build/2.3.7/koffi_linux_arm32hf/koffi.node +0 -0
  12. package/src/koffi/build/2.3.7/koffi_linux_arm64/koffi.node +0 -0
  13. package/src/koffi/build/2.3.7/koffi_linux_ia32/koffi.node +0 -0
  14. package/src/koffi/build/2.3.7/koffi_linux_riscv64hf64/koffi.node +0 -0
  15. package/src/koffi/build/2.3.7/koffi_linux_x64/koffi.node +0 -0
  16. package/src/koffi/build/2.3.7/koffi_openbsd_ia32/koffi.node +0 -0
  17. package/src/koffi/build/2.3.7/koffi_openbsd_x64/koffi.node +0 -0
  18. package/src/koffi/build/2.3.7/koffi_win32_arm64/koffi.node +0 -0
  19. package/src/koffi/build/2.3.7/koffi_win32_ia32/koffi.node +0 -0
  20. package/src/koffi/build/2.3.7/koffi_win32_x64/koffi.node +0 -0
  21. package/src/koffi/src/ffi.cc +2 -2
  22. package/src/koffi/src/index.d.ts +2 -2
  23. package/src/koffi/src/index.js +1 -0
  24. package/src/koffi/build/2.3.6-beta.6/koffi_darwin_arm64/koffi.node +0 -0
  25. package/src/koffi/build/2.3.6-beta.6/koffi_darwin_x64/koffi.node +0 -0
  26. package/src/koffi/build/2.3.6-beta.6/koffi_freebsd_arm64/koffi.node +0 -0
  27. package/src/koffi/build/2.3.6-beta.6/koffi_freebsd_ia32/koffi.node +0 -0
  28. package/src/koffi/build/2.3.6-beta.6/koffi_freebsd_x64/koffi.node +0 -0
  29. package/src/koffi/build/2.3.6-beta.6/koffi_linux_arm32hf/koffi.node +0 -0
  30. package/src/koffi/build/2.3.6-beta.6/koffi_linux_arm64/koffi.node +0 -0
  31. package/src/koffi/build/2.3.6-beta.6/koffi_linux_ia32/koffi.node +0 -0
  32. package/src/koffi/build/2.3.6-beta.6/koffi_linux_riscv64hf64/koffi.node +0 -0
  33. package/src/koffi/build/2.3.6-beta.6/koffi_linux_x64/koffi.node +0 -0
  34. package/src/koffi/build/2.3.6-beta.6/koffi_openbsd_ia32/koffi.node +0 -0
  35. package/src/koffi/build/2.3.6-beta.6/koffi_openbsd_x64/koffi.node +0 -0
  36. package/src/koffi/build/2.3.6-beta.6/koffi_win32_arm64/koffi.node +0 -0
  37. package/src/koffi/build/2.3.6-beta.6/koffi_win32_arm64/koffi.pdb +0 -0
  38. package/src/koffi/build/2.3.6-beta.6/koffi_win32_ia32/koffi.node +0 -0
  39. package/src/koffi/build/2.3.6-beta.6/koffi_win32_ia32/koffi.pdb +0 -0
  40. package/src/koffi/build/2.3.6-beta.6/koffi_win32_x64/koffi.node +0 -0
  41. package/src/koffi/build/2.3.6-beta.6/koffi_win32_x64/koffi.pdb +0 -0
  42. package/vendor/brotli/BUILD +0 -144
  43. package/vendor/brotli/CMakeLists.txt +0 -421
  44. package/vendor/brotli/CONTRIBUTING.md +0 -27
  45. package/vendor/brotli/LICENSE +0 -19
  46. package/vendor/brotli/MANIFEST.in +0 -17
  47. package/vendor/brotli/Makefile +0 -55
  48. package/vendor/brotli/Makefile.am +0 -38
  49. package/vendor/brotli/README +0 -15
  50. package/vendor/brotli/README.md +0 -104
  51. package/vendor/brotli/WORKSPACE +0 -21
  52. package/vendor/brotli/bootstrap +0 -35
  53. package/vendor/brotli/c/common/constants.c +0 -15
  54. package/vendor/brotli/c/common/constants.h +0 -200
  55. package/vendor/brotli/c/common/context.c +0 -156
  56. package/vendor/brotli/c/common/context.h +0 -113
  57. package/vendor/brotli/c/common/dictionary.c +0 -5914
  58. package/vendor/brotli/c/common/dictionary.h +0 -64
  59. package/vendor/brotli/c/common/platform.c +0 -22
  60. package/vendor/brotli/c/common/platform.h +0 -596
  61. package/vendor/brotli/c/common/transform.c +0 -291
  62. package/vendor/brotli/c/common/transform.h +0 -85
  63. package/vendor/brotli/c/common/version.h +0 -26
  64. package/vendor/brotli/c/dec/bit_reader.c +0 -76
  65. package/vendor/brotli/c/dec/bit_reader.h +0 -351
  66. package/vendor/brotli/c/dec/decode.c +0 -2608
  67. package/vendor/brotli/c/dec/huffman.c +0 -339
  68. package/vendor/brotli/c/dec/huffman.h +0 -121
  69. package/vendor/brotli/c/dec/prefix.h +0 -732
  70. package/vendor/brotli/c/dec/state.c +0 -159
  71. package/vendor/brotli/c/dec/state.h +0 -365
  72. package/vendor/brotli/c/enc/backward_references.c +0 -145
  73. package/vendor/brotli/c/enc/backward_references.h +0 -39
  74. package/vendor/brotli/c/enc/backward_references_hq.c +0 -843
  75. package/vendor/brotli/c/enc/backward_references_hq.h +0 -95
  76. package/vendor/brotli/c/enc/backward_references_inc.h +0 -163
  77. package/vendor/brotli/c/enc/bit_cost.c +0 -35
  78. package/vendor/brotli/c/enc/bit_cost.h +0 -63
  79. package/vendor/brotli/c/enc/bit_cost_inc.h +0 -127
  80. package/vendor/brotli/c/enc/block_encoder_inc.h +0 -34
  81. package/vendor/brotli/c/enc/block_splitter.c +0 -194
  82. package/vendor/brotli/c/enc/block_splitter.h +0 -51
  83. package/vendor/brotli/c/enc/block_splitter_inc.h +0 -440
  84. package/vendor/brotli/c/enc/brotli_bit_stream.c +0 -1314
  85. package/vendor/brotli/c/enc/brotli_bit_stream.h +0 -84
  86. package/vendor/brotli/c/enc/cluster.c +0 -56
  87. package/vendor/brotli/c/enc/cluster.h +0 -48
  88. package/vendor/brotli/c/enc/cluster_inc.h +0 -320
  89. package/vendor/brotli/c/enc/command.c +0 -28
  90. package/vendor/brotli/c/enc/command.h +0 -190
  91. package/vendor/brotli/c/enc/compress_fragment.c +0 -790
  92. package/vendor/brotli/c/enc/compress_fragment.h +0 -61
  93. package/vendor/brotli/c/enc/compress_fragment_two_pass.c +0 -645
  94. package/vendor/brotli/c/enc/compress_fragment_two_pass.h +0 -54
  95. package/vendor/brotli/c/enc/dictionary_hash.c +0 -1846
  96. package/vendor/brotli/c/enc/dictionary_hash.h +0 -25
  97. package/vendor/brotli/c/enc/encode.c +0 -1927
  98. package/vendor/brotli/c/enc/encoder_dict.c +0 -33
  99. package/vendor/brotli/c/enc/encoder_dict.h +0 -43
  100. package/vendor/brotli/c/enc/entropy_encode.c +0 -503
  101. package/vendor/brotli/c/enc/entropy_encode.h +0 -122
  102. package/vendor/brotli/c/enc/entropy_encode_static.h +0 -539
  103. package/vendor/brotli/c/enc/fast_log.c +0 -105
  104. package/vendor/brotli/c/enc/fast_log.h +0 -66
  105. package/vendor/brotli/c/enc/find_match_length.h +0 -79
  106. package/vendor/brotli/c/enc/hash.h +0 -488
  107. package/vendor/brotli/c/enc/hash_composite_inc.h +0 -125
  108. package/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +0 -293
  109. package/vendor/brotli/c/enc/hash_longest_match64_inc.h +0 -267
  110. package/vendor/brotli/c/enc/hash_longest_match_inc.h +0 -262
  111. package/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +0 -266
  112. package/vendor/brotli/c/enc/hash_rolling_inc.h +0 -212
  113. package/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +0 -329
  114. package/vendor/brotli/c/enc/histogram.c +0 -100
  115. package/vendor/brotli/c/enc/histogram.h +0 -63
  116. package/vendor/brotli/c/enc/histogram_inc.h +0 -51
  117. package/vendor/brotli/c/enc/literal_cost.c +0 -175
  118. package/vendor/brotli/c/enc/literal_cost.h +0 -30
  119. package/vendor/brotli/c/enc/memory.c +0 -170
  120. package/vendor/brotli/c/enc/memory.h +0 -114
  121. package/vendor/brotli/c/enc/metablock.c +0 -663
  122. package/vendor/brotli/c/enc/metablock.h +0 -105
  123. package/vendor/brotli/c/enc/metablock_inc.h +0 -183
  124. package/vendor/brotli/c/enc/params.h +0 -46
  125. package/vendor/brotli/c/enc/prefix.h +0 -53
  126. package/vendor/brotli/c/enc/quality.h +0 -165
  127. package/vendor/brotli/c/enc/ringbuffer.h +0 -167
  128. package/vendor/brotli/c/enc/static_dict.c +0 -486
  129. package/vendor/brotli/c/enc/static_dict.h +0 -40
  130. package/vendor/brotli/c/enc/static_dict_lut.h +0 -5864
  131. package/vendor/brotli/c/enc/utf8_util.c +0 -85
  132. package/vendor/brotli/c/enc/utf8_util.h +0 -32
  133. package/vendor/brotli/c/enc/write_bits.h +0 -87
  134. package/vendor/brotli/c/include/brotli/decode.h +0 -344
  135. package/vendor/brotli/c/include/brotli/encode.h +0 -448
  136. package/vendor/brotli/c/include/brotli/port.h +0 -288
  137. package/vendor/brotli/c/include/brotli/types.h +0 -83
  138. package/vendor/brotli/c/tools/brotli.c +0 -1116
  139. package/vendor/brotli/c/tools/brotli.md +0 -107
  140. package/vendor/brotli/compiler_config_setting.bzl +0 -28
  141. package/vendor/brotli/configure +0 -8
  142. package/vendor/brotli/configure-cmake +0 -318
  143. package/vendor/brotli/configure.ac +0 -14
  144. package/vendor/brotli/docs/brotli.1 +0 -132
  145. package/vendor/brotli/docs/constants.h.3 +0 -47
  146. package/vendor/brotli/docs/decode.h.3 +0 -415
  147. package/vendor/brotli/docs/encode.h.3 +0 -586
  148. package/vendor/brotli/docs/types.h.3 +0 -117
  149. package/vendor/brotli/premake5.lua +0 -78
  150. package/vendor/brotli/python/Makefile +0 -57
  151. package/vendor/brotli/python/README.md +0 -54
  152. package/vendor/brotli/python/_brotli.cc +0 -753
  153. package/vendor/brotli/python/bro.py +0 -160
  154. package/vendor/brotli/python/brotli.py +0 -56
  155. package/vendor/brotli/python/tests/__init__.py +0 -0
  156. package/vendor/brotli/python/tests/_test_utils.py +0 -112
  157. package/vendor/brotli/python/tests/bro_test.py +0 -102
  158. package/vendor/brotli/python/tests/compress_test.py +0 -41
  159. package/vendor/brotli/python/tests/compressor_test.py +0 -94
  160. package/vendor/brotli/python/tests/decompress_test.py +0 -42
  161. package/vendor/brotli/python/tests/decompressor_test.py +0 -59
  162. package/vendor/brotli/scripts/libbrotlicommon.pc.in +0 -11
  163. package/vendor/brotli/scripts/libbrotlidec.pc.in +0 -12
  164. package/vendor/brotli/scripts/libbrotlienc.pc.in +0 -12
  165. package/vendor/brotli/scripts/sources.lst +0 -104
  166. package/vendor/brotli/setup.cfg +0 -5
  167. package/vendor/brotli/setup.py +0 -293
  168. package/vendor/brotli/tests/Makefile +0 -17
  169. package/vendor/brotli/tests/compatibility_test.sh +0 -25
  170. package/vendor/brotli/tests/roundtrip_test.sh +0 -36
  171. package/vendor/brotli/tests/run-compatibility-test.cmake +0 -31
  172. package/vendor/brotli/tests/run-roundtrip-test.cmake +0 -36
  173. package/vendor/brotli/tests/testdata/empty +0 -0
  174. package/vendor/brotli/tests/testdata/empty.compressed +0 -1
  175. package/vendor/brotli/tests/testdata/ukkonooa +0 -1
  176. package/vendor/brotli/tests/testdata/ukkonooa.compressed +0 -0
  177. package/vendor/dragonbox/CMakeLists.txt +0 -123
  178. package/vendor/dragonbox/LICENSE-Apache2-LLVM +0 -218
  179. package/vendor/dragonbox/LICENSE-Boost +0 -23
  180. package/vendor/dragonbox/README.md +0 -277
  181. package/vendor/dragonbox/cmake/dragonboxConfig.cmake +0 -1
  182. package/vendor/dragonbox/include/dragonbox/dragonbox.h +0 -2674
  183. package/vendor/dragonbox/include/dragonbox/dragonbox_to_chars.h +0 -108
  184. package/vendor/dragonbox/other_files/Dragonbox.pdf +0 -0
  185. package/vendor/dragonbox/other_files/Dragonbox_old.pdf +0 -0
  186. package/vendor/dragonbox/other_files/milo_benchmark.png +0 -0
  187. package/vendor/dragonbox/other_files/unknown_win64_vc2019.html +0 -540
  188. package/vendor/dragonbox/other_files/unknown_win64_vc2019_randomdigit_time.png +0 -0
  189. package/vendor/dragonbox/source/dragonbox_to_chars.cpp +0 -303
  190. package/vendor/dragonbox/subproject/3rdparty/grisu_exact/CMakeLists.txt +0 -24
  191. package/vendor/dragonbox/subproject/3rdparty/grisu_exact/fp_to_chars.cpp +0 -238
  192. package/vendor/dragonbox/subproject/3rdparty/grisu_exact/fp_to_chars.h +0 -95
  193. package/vendor/dragonbox/subproject/3rdparty/grisu_exact/grisu_exact.h +0 -2666
  194. package/vendor/dragonbox/subproject/3rdparty/ryu/CMakeLists.txt +0 -16
  195. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/common.h +0 -114
  196. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s.c +0 -509
  197. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s_full_table.h +0 -367
  198. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s_intrinsics.h +0 -357
  199. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/digit_table.h +0 -35
  200. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s.c +0 -345
  201. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s_full_table.h +0 -55
  202. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s_intrinsics.h +0 -128
  203. package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/ryu.h +0 -46
  204. package/vendor/dragonbox/subproject/3rdparty/schubfach/CMakeLists.txt +0 -22
  205. package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_32.cc +0 -699
  206. package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_32.h +0 -31
  207. package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_64.cc +0 -1354
  208. package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_64.h +0 -31
  209. package/vendor/dragonbox/subproject/3rdparty/shaded_plots/example_shaded_plots.m +0 -68
  210. package/vendor/dragonbox/subproject/3rdparty/shaded_plots/license.txt +0 -25
  211. package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_distribution.m +0 -92
  212. package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_distribution_prctile.m +0 -121
  213. package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_histogram_shaded.m +0 -99
  214. package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_shaded.m +0 -93
  215. package/vendor/dragonbox/subproject/benchmark/CMakeLists.txt +0 -65
  216. package/vendor/dragonbox/subproject/benchmark/include/benchmark.h +0 -40
  217. package/vendor/dragonbox/subproject/benchmark/matlab/plot_benchmarks.m +0 -22
  218. package/vendor/dragonbox/subproject/benchmark/matlab/plot_digit_benchmark.m +0 -78
  219. package/vendor/dragonbox/subproject/benchmark/matlab/plot_uniform_benchmark.m +0 -95
  220. package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary32_clang.png +0 -0
  221. package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary32_msvc.png +0 -0
  222. package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary64_clang.png +0 -0
  223. package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary64_msvc.png +0 -0
  224. package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary32_clang.png +0 -0
  225. package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary32_msvc.png +0 -0
  226. package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary64_clang.png +0 -0
  227. package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary64_msvc.png +0 -0
  228. package/vendor/dragonbox/subproject/benchmark/source/benchmark.cpp +0 -238
  229. package/vendor/dragonbox/subproject/benchmark/source/dragonbox.cpp +0 -30
  230. package/vendor/dragonbox/subproject/benchmark/source/grisu_exact.cpp +0 -36
  231. package/vendor/dragonbox/subproject/benchmark/source/ryu.cpp +0 -27
  232. package/vendor/dragonbox/subproject/benchmark/source/schubfach.cpp +0 -31
  233. package/vendor/dragonbox/subproject/common/CMakeLists.txt +0 -42
  234. package/vendor/dragonbox/subproject/common/include/best_rational_approx.h +0 -97
  235. package/vendor/dragonbox/subproject/common/include/big_uint.h +0 -218
  236. package/vendor/dragonbox/subproject/common/include/continued_fractions.h +0 -174
  237. package/vendor/dragonbox/subproject/common/include/good_rational_approx.h +0 -267
  238. package/vendor/dragonbox/subproject/common/include/random_float.h +0 -182
  239. package/vendor/dragonbox/subproject/common/include/rational_continued_fractions.h +0 -57
  240. package/vendor/dragonbox/subproject/common/source/big_uint.cpp +0 -602
  241. package/vendor/dragonbox/subproject/meta/CMakeLists.txt +0 -41
  242. package/vendor/dragonbox/subproject/meta/results/binary32_generated_cache.txt +0 -82
  243. package/vendor/dragonbox/subproject/meta/results/binary64_compressed_cache_error_table.txt +0 -10
  244. package/vendor/dragonbox/subproject/meta/results/binary64_generated_cache.txt +0 -623
  245. package/vendor/dragonbox/subproject/meta/source/generate_cache.cpp +0 -126
  246. package/vendor/dragonbox/subproject/meta/source/live_test.cpp +0 -81
  247. package/vendor/dragonbox/subproject/meta/source/perf_test.cpp +0 -104
  248. package/vendor/dragonbox/subproject/meta/source/sandbox.cpp +0 -20
  249. package/vendor/dragonbox/subproject/test/CMakeLists.txt +0 -70
  250. package/vendor/dragonbox/subproject/test/results/binary32.csv +0 -255
  251. package/vendor/dragonbox/subproject/test/results/binary64.csv +0 -2047
  252. package/vendor/dragonbox/subproject/test/results/plot_required_bits.m +0 -18
  253. package/vendor/dragonbox/subproject/test/source/test_all_shorter_interval_cases.cpp +0 -88
  254. package/vendor/dragonbox/subproject/test/source/uniform_random_test.cpp +0 -95
  255. package/vendor/dragonbox/subproject/test/source/verify_cache_precision.cpp +0 -338
  256. package/vendor/dragonbox/subproject/test/source/verify_compressed_cache.cpp +0 -154
  257. package/vendor/dragonbox/subproject/test/source/verify_fast_multiplication.cpp +0 -168
  258. package/vendor/dragonbox/subproject/test/source/verify_log_computation.cpp +0 -251
  259. package/vendor/dragonbox/subproject/test/source/verify_magic_division.cpp +0 -113
  260. package/vendor/miniz/ChangeLog.md +0 -239
  261. package/vendor/miniz/LICENSE +0 -22
  262. package/vendor/miniz/examples/example1.c +0 -105
  263. package/vendor/miniz/examples/example2.c +0 -164
  264. package/vendor/miniz/examples/example3.c +0 -269
  265. package/vendor/miniz/examples/example4.c +0 -102
  266. package/vendor/miniz/examples/example5.c +0 -327
  267. package/vendor/miniz/examples/example6.c +0 -166
  268. package/vendor/miniz/miniz.c +0 -7835
  269. package/vendor/miniz/miniz.h +0 -1422
  270. package/vendor/miniz/readme.md +0 -46
  271. /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_arm64/koffi.exp +0 -0
  272. /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_arm64/koffi.lib +0 -0
  273. /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_ia32/koffi.exp +0 -0
  274. /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_ia32/koffi.lib +0 -0
  275. /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_x64/koffi.exp +0 -0
  276. /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_x64/koffi.lib +0 -0
@@ -1,16 +0,0 @@
1
- cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
2
-
3
- project(ryu_cmake LANGUAGES C)
4
-
5
- add_library(ryu STATIC
6
- ryu/ryu.h ryu/common.h ryu/f2s.c ryu/d2s.c
7
- ryu/f2s_intrinsics.h ryu/f2s_full_table.h
8
- ryu/d2s_intrinsics.h ryu/d2s_full_table.h
9
- ryu/digit_table.h)
10
- add_library(ryu::ryu ALIAS ryu)
11
-
12
- target_compile_features(ryu PUBLIC cxx_std_17)
13
-
14
- target_include_directories(ryu
15
- PUBLIC
16
- $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>)
@@ -1,114 +0,0 @@
1
- // Copyright 2018 Ulf Adams
2
- //
3
- // The contents of this file may be used under the terms of the Apache License,
4
- // Version 2.0.
5
- //
6
- // (See accompanying file LICENSE-Apache or copy at
7
- // http://www.apache.org/licenses/LICENSE-2.0)
8
- //
9
- // Alternatively, the contents of this file may be used under the terms of
10
- // the Boost Software License, Version 1.0.
11
- // (See accompanying file LICENSE-Boost or copy at
12
- // https://www.boost.org/LICENSE_1_0.txt)
13
- //
14
- // Unless required by applicable law or agreed to in writing, this software
15
- // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- // KIND, either express or implied.
17
- #ifndef RYU_COMMON_H
18
- #define RYU_COMMON_H
19
-
20
- #include <assert.h>
21
- #include <stdint.h>
22
- #include <string.h>
23
-
24
- #if defined(_M_IX86) || defined(_M_ARM)
25
- #define RYU_32_BIT_PLATFORM
26
- #endif
27
-
28
- // Returns the number of decimal digits in v, which must not contain more than 9 digits.
29
- static inline uint32_t decimalLength9(const uint32_t v) {
30
- // Function precondition: v is not a 10-digit number.
31
- // (f2s: 9 digits are sufficient for round-tripping.)
32
- // (d2fixed: We print 9-digit blocks.)
33
- assert(v < 1000000000);
34
- if (v >= 100000000) { return 9; }
35
- if (v >= 10000000) { return 8; }
36
- if (v >= 1000000) { return 7; }
37
- if (v >= 100000) { return 6; }
38
- if (v >= 10000) { return 5; }
39
- if (v >= 1000) { return 4; }
40
- if (v >= 100) { return 3; }
41
- if (v >= 10) { return 2; }
42
- return 1;
43
- }
44
-
45
- // Returns e == 0 ? 1 : [log_2(5^e)]; requires 0 <= e <= 3528.
46
- static inline int32_t log2pow5(const int32_t e) {
47
- // This approximation works up to the point that the multiplication overflows at e = 3529.
48
- // If the multiplication were done in 64 bits, it would fail at 5^4004 which is just greater
49
- // than 2^9297.
50
- assert(e >= 0);
51
- assert(e <= 3528);
52
- return (int32_t) ((((uint32_t) e) * 1217359) >> 19);
53
- }
54
-
55
- // Returns e == 0 ? 1 : ceil(log_2(5^e)); requires 0 <= e <= 3528.
56
- static inline int32_t pow5bits(const int32_t e) {
57
- // This approximation works up to the point that the multiplication overflows at e = 3529.
58
- // If the multiplication were done in 64 bits, it would fail at 5^4004 which is just greater
59
- // than 2^9297.
60
- assert(e >= 0);
61
- assert(e <= 3528);
62
- return (int32_t) (((((uint32_t) e) * 1217359) >> 19) + 1);
63
- }
64
-
65
- // Returns e == 0 ? 1 : ceil(log_2(5^e)); requires 0 <= e <= 3528.
66
- static inline int32_t ceil_log2pow5(const int32_t e) {
67
- return log2pow5(e) + 1;
68
- }
69
-
70
- // Returns floor(log_10(2^e)); requires 0 <= e <= 1650.
71
- static inline uint32_t log10Pow2(const int32_t e) {
72
- // The first value this approximation fails for is 2^1651 which is just greater than 10^297.
73
- assert(e >= 0);
74
- assert(e <= 1650);
75
- return (((uint32_t) e) * 78913) >> 18;
76
- }
77
-
78
- // Returns floor(log_10(5^e)); requires 0 <= e <= 2620.
79
- static inline uint32_t log10Pow5(const int32_t e) {
80
- // The first value this approximation fails for is 5^2621 which is just greater than 10^1832.
81
- assert(e >= 0);
82
- assert(e <= 2620);
83
- return (((uint32_t) e) * 732923) >> 20;
84
- }
85
-
86
- static inline int copy_special_str(char * const result, const bool sign, const bool exponent, const bool mantissa) {
87
- if (mantissa) {
88
- memcpy(result, "NaN", 3);
89
- return 3;
90
- }
91
- if (sign) {
92
- result[0] = '-';
93
- }
94
- if (exponent) {
95
- memcpy(result + sign, "Infinity", 8);
96
- return sign + 8;
97
- }
98
- memcpy(result + sign, "0E0", 3);
99
- return sign + 3;
100
- }
101
-
102
- static inline uint32_t float_to_bits(const float f) {
103
- uint32_t bits = 0;
104
- memcpy(&bits, &f, sizeof(float));
105
- return bits;
106
- }
107
-
108
- static inline uint64_t double_to_bits(const double d) {
109
- uint64_t bits = 0;
110
- memcpy(&bits, &d, sizeof(double));
111
- return bits;
112
- }
113
-
114
- #endif // RYU_COMMON_H
@@ -1,509 +0,0 @@
1
- // Copyright 2018 Ulf Adams
2
- //
3
- // The contents of this file may be used under the terms of the Apache License,
4
- // Version 2.0.
5
- //
6
- // (See accompanying file LICENSE-Apache or copy at
7
- // http://www.apache.org/licenses/LICENSE-2.0)
8
- //
9
- // Alternatively, the contents of this file may be used under the terms of
10
- // the Boost Software License, Version 1.0.
11
- // (See accompanying file LICENSE-Boost or copy at
12
- // https://www.boost.org/LICENSE_1_0.txt)
13
- //
14
- // Unless required by applicable law or agreed to in writing, this software
15
- // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
- // KIND, either express or implied.
17
-
18
- // Runtime compiler options:
19
- // -DRYU_DEBUG Generate verbose debugging output to stdout.
20
- //
21
- // -DRYU_ONLY_64_BIT_OPS Avoid using uint128_t or 64-bit intrinsics. Slower,
22
- // depending on your compiler.
23
- //
24
- // -DRYU_OPTIMIZE_SIZE Use smaller lookup tables. Instead of storing every
25
- // required power of 5, only store every 26th entry, and compute
26
- // intermediate values with a multiplication. This reduces the lookup table
27
- // size by about 10x (only one case, and only double) at the cost of some
28
- // performance. Currently requires MSVC intrinsics.
29
-
30
- #include "ryu/ryu.h"
31
-
32
- #include <assert.h>
33
- #include <stdbool.h>
34
- #include <stdint.h>
35
- #include <stdlib.h>
36
- #include <string.h>
37
-
38
- #ifdef RYU_DEBUG
39
- #include <inttypes.h>
40
- #include <stdio.h>
41
- #endif
42
-
43
- #include "ryu/common.h"
44
- #include "ryu/digit_table.h"
45
- #include "ryu/d2s_intrinsics.h"
46
-
47
- // Include either the small or the full lookup tables depending on the mode.
48
- #if defined(RYU_OPTIMIZE_SIZE)
49
- #include "ryu/d2s_small_table.h"
50
- #else
51
- #include "ryu/d2s_full_table.h"
52
- #endif
53
-
54
- #define DOUBLE_MANTISSA_BITS 52
55
- #define DOUBLE_EXPONENT_BITS 11
56
- #define DOUBLE_BIAS 1023
57
-
58
- static inline uint32_t decimalLength17(const uint64_t v) {
59
- // This is slightly faster than a loop.
60
- // The average output length is 16.38 digits, so we check high-to-low.
61
- // Function precondition: v is not an 18, 19, or 20-digit number.
62
- // (17 digits are sufficient for round-tripping.)
63
- assert(v < 100000000000000000L);
64
- if (v >= 10000000000000000L) { return 17; }
65
- if (v >= 1000000000000000L) { return 16; }
66
- if (v >= 100000000000000L) { return 15; }
67
- if (v >= 10000000000000L) { return 14; }
68
- if (v >= 1000000000000L) { return 13; }
69
- if (v >= 100000000000L) { return 12; }
70
- if (v >= 10000000000L) { return 11; }
71
- if (v >= 1000000000L) { return 10; }
72
- if (v >= 100000000L) { return 9; }
73
- if (v >= 10000000L) { return 8; }
74
- if (v >= 1000000L) { return 7; }
75
- if (v >= 100000L) { return 6; }
76
- if (v >= 10000L) { return 5; }
77
- if (v >= 1000L) { return 4; }
78
- if (v >= 100L) { return 3; }
79
- if (v >= 10L) { return 2; }
80
- return 1;
81
- }
82
-
83
- // A floating decimal representing m * 10^e.
84
- typedef struct floating_decimal_64 {
85
- uint64_t mantissa;
86
- // Decimal exponent's range is -324 to 308
87
- // inclusive, and can fit in a short if needed.
88
- int32_t exponent;
89
- } floating_decimal_64;
90
-
91
- static inline floating_decimal_64 d2d(const uint64_t ieeeMantissa, const uint32_t ieeeExponent) {
92
- int32_t e2;
93
- uint64_t m2;
94
- if (ieeeExponent == 0) {
95
- // We subtract 2 so that the bounds computation has 2 additional bits.
96
- e2 = 1 - DOUBLE_BIAS - DOUBLE_MANTISSA_BITS - 2;
97
- m2 = ieeeMantissa;
98
- } else {
99
- e2 = (int32_t) ieeeExponent - DOUBLE_BIAS - DOUBLE_MANTISSA_BITS - 2;
100
- m2 = (1ull << DOUBLE_MANTISSA_BITS) | ieeeMantissa;
101
- }
102
- const bool even = (m2 & 1) == 0;
103
- const bool acceptBounds = even;
104
-
105
- #ifdef RYU_DEBUG
106
- printf("-> %" PRIu64 " * 2^%d\n", m2, e2 + 2);
107
- #endif
108
-
109
- // Step 2: Determine the interval of valid decimal representations.
110
- const uint64_t mv = 4 * m2;
111
- // Implicit bool -> int conversion. True is 1, false is 0.
112
- const uint32_t mmShift = ieeeMantissa != 0 || ieeeExponent <= 1;
113
- // We would compute mp and mm like this:
114
- // uint64_t mp = 4 * m2 + 2;
115
- // uint64_t mm = mv - 1 - mmShift;
116
-
117
- // Step 3: Convert to a decimal power base using 128-bit arithmetic.
118
- uint64_t vr, vp, vm;
119
- int32_t e10;
120
- bool vmIsTrailingZeros = false;
121
- bool vrIsTrailingZeros = false;
122
- if (e2 >= 0) {
123
- // I tried special-casing q == 0, but there was no effect on performance.
124
- // This expression is slightly faster than max(0, log10Pow2(e2) - 1).
125
- const uint32_t q = log10Pow2(e2) - (e2 > 3);
126
- e10 = (int32_t) q;
127
- const int32_t k = DOUBLE_POW5_INV_BITCOUNT + pow5bits((int32_t) q) - 1;
128
- const int32_t i = -e2 + (int32_t) q + k;
129
- #if defined(RYU_OPTIMIZE_SIZE)
130
- uint64_t pow5[2];
131
- double_computeInvPow5(q, pow5);
132
- vr = mulShiftAll64(m2, pow5, i, &vp, &vm, mmShift);
133
- #else
134
- vr = mulShiftAll64(m2, DOUBLE_POW5_INV_SPLIT[q], i, &vp, &vm, mmShift);
135
- #endif
136
- #ifdef RYU_DEBUG
137
- printf("%" PRIu64 " * 2^%d / 10^%u\n", mv, e2, q);
138
- printf("V+=%" PRIu64 "\nV =%" PRIu64 "\nV-=%" PRIu64 "\n", vp, vr, vm);
139
- #endif
140
- if (q <= 21) {
141
- // This should use q <= 22, but I think 21 is also safe. Smaller values
142
- // may still be safe, but it's more difficult to reason about them.
143
- // Only one of mp, mv, and mm can be a multiple of 5, if any.
144
- const uint32_t mvMod5 = ((uint32_t) mv) - 5 * ((uint32_t) div5(mv));
145
- if (mvMod5 == 0) {
146
- vrIsTrailingZeros = multipleOfPowerOf5(mv, q);
147
- } else if (acceptBounds) {
148
- // Same as min(e2 + (~mm & 1), pow5Factor(mm)) >= q
149
- // <=> e2 + (~mm & 1) >= q && pow5Factor(mm) >= q
150
- // <=> true && pow5Factor(mm) >= q, since e2 >= q.
151
- vmIsTrailingZeros = multipleOfPowerOf5(mv - 1 - mmShift, q);
152
- } else {
153
- // Same as min(e2 + 1, pow5Factor(mp)) >= q.
154
- vp -= multipleOfPowerOf5(mv + 2, q);
155
- }
156
- }
157
- } else {
158
- // This expression is slightly faster than max(0, log10Pow5(-e2) - 1).
159
- const uint32_t q = log10Pow5(-e2) - (-e2 > 1);
160
- e10 = (int32_t) q + e2;
161
- const int32_t i = -e2 - (int32_t) q;
162
- const int32_t k = pow5bits(i) - DOUBLE_POW5_BITCOUNT;
163
- const int32_t j = (int32_t) q - k;
164
- #if defined(RYU_OPTIMIZE_SIZE)
165
- uint64_t pow5[2];
166
- double_computePow5(i, pow5);
167
- vr = mulShiftAll64(m2, pow5, j, &vp, &vm, mmShift);
168
- #else
169
- vr = mulShiftAll64(m2, DOUBLE_POW5_SPLIT[i], j, &vp, &vm, mmShift);
170
- #endif
171
- #ifdef RYU_DEBUG
172
- printf("%" PRIu64 " * 5^%d / 10^%u\n", mv, -e2, q);
173
- printf("%u %d %d %d\n", q, i, k, j);
174
- printf("V+=%" PRIu64 "\nV =%" PRIu64 "\nV-=%" PRIu64 "\n", vp, vr, vm);
175
- #endif
176
- if (q <= 1) {
177
- // {vr,vp,vm} is trailing zeros if {mv,mp,mm} has at least q trailing 0 bits.
178
- // mv = 4 * m2, so it always has at least two trailing 0 bits.
179
- vrIsTrailingZeros = true;
180
- if (acceptBounds) {
181
- // mm = mv - 1 - mmShift, so it has 1 trailing 0 bit iff mmShift == 1.
182
- vmIsTrailingZeros = mmShift == 1;
183
- } else {
184
- // mp = mv + 2, so it always has at least one trailing 0 bit.
185
- --vp;
186
- }
187
- } else if (q < 63) { // TODO(ulfjack): Use a tighter bound here.
188
- // We want to know if the full product has at least q trailing zeros.
189
- // We need to compute min(p2(mv), p5(mv) - e2) >= q
190
- // <=> p2(mv) >= q && p5(mv) - e2 >= q
191
- // <=> p2(mv) >= q (because -e2 >= q)
192
- vrIsTrailingZeros = multipleOfPowerOf2(mv, q);
193
- #ifdef RYU_DEBUG
194
- printf("vr is trailing zeros=%s\n", vrIsTrailingZeros ? "true" : "false");
195
- #endif
196
- }
197
- }
198
- #ifdef RYU_DEBUG
199
- printf("e10=%d\n", e10);
200
- printf("V+=%" PRIu64 "\nV =%" PRIu64 "\nV-=%" PRIu64 "\n", vp, vr, vm);
201
- printf("vm is trailing zeros=%s\n", vmIsTrailingZeros ? "true" : "false");
202
- printf("vr is trailing zeros=%s\n", vrIsTrailingZeros ? "true" : "false");
203
- #endif
204
-
205
- // Step 4: Find the shortest decimal representation in the interval of valid representations.
206
- int32_t removed = 0;
207
- uint8_t lastRemovedDigit = 0;
208
- uint64_t output;
209
- // On average, we remove ~2 digits.
210
- if (vmIsTrailingZeros || vrIsTrailingZeros) {
211
- // General case, which happens rarely (~0.7%).
212
- for (;;) {
213
- const uint64_t vpDiv10 = div10(vp);
214
- const uint64_t vmDiv10 = div10(vm);
215
- if (vpDiv10 <= vmDiv10) {
216
- break;
217
- }
218
- const uint32_t vmMod10 = ((uint32_t) vm) - 10 * ((uint32_t) vmDiv10);
219
- const uint64_t vrDiv10 = div10(vr);
220
- const uint32_t vrMod10 = ((uint32_t) vr) - 10 * ((uint32_t) vrDiv10);
221
- vmIsTrailingZeros &= vmMod10 == 0;
222
- vrIsTrailingZeros &= lastRemovedDigit == 0;
223
- lastRemovedDigit = (uint8_t) vrMod10;
224
- vr = vrDiv10;
225
- vp = vpDiv10;
226
- vm = vmDiv10;
227
- ++removed;
228
- }
229
- #ifdef RYU_DEBUG
230
- printf("V+=%" PRIu64 "\nV =%" PRIu64 "\nV-=%" PRIu64 "\n", vp, vr, vm);
231
- printf("d-10=%s\n", vmIsTrailingZeros ? "true" : "false");
232
- #endif
233
- if (vmIsTrailingZeros) {
234
- for (;;) {
235
- const uint64_t vmDiv10 = div10(vm);
236
- const uint32_t vmMod10 = ((uint32_t) vm) - 10 * ((uint32_t) vmDiv10);
237
- if (vmMod10 != 0) {
238
- break;
239
- }
240
- const uint64_t vpDiv10 = div10(vp);
241
- const uint64_t vrDiv10 = div10(vr);
242
- const uint32_t vrMod10 = ((uint32_t) vr) - 10 * ((uint32_t) vrDiv10);
243
- vrIsTrailingZeros &= lastRemovedDigit == 0;
244
- lastRemovedDigit = (uint8_t) vrMod10;
245
- vr = vrDiv10;
246
- vp = vpDiv10;
247
- vm = vmDiv10;
248
- ++removed;
249
- }
250
- }
251
- #ifdef RYU_DEBUG
252
- printf("%" PRIu64 " %d\n", vr, lastRemovedDigit);
253
- printf("vr is trailing zeros=%s\n", vrIsTrailingZeros ? "true" : "false");
254
- #endif
255
- if (vrIsTrailingZeros && lastRemovedDigit == 5 && vr % 2 == 0) {
256
- // Round even if the exact number is .....50..0.
257
- lastRemovedDigit = 4;
258
- }
259
- // We need to take vr + 1 if vr is outside bounds or we need to round up.
260
- output = vr + ((vr == vm && (!acceptBounds || !vmIsTrailingZeros)) || lastRemovedDigit >= 5);
261
- } else {
262
- // Specialized for the common case (~99.3%). Percentages below are relative to this.
263
- bool roundUp = false;
264
- const uint64_t vpDiv100 = div100(vp);
265
- const uint64_t vmDiv100 = div100(vm);
266
- if (vpDiv100 > vmDiv100) { // Optimization: remove two digits at a time (~86.2%).
267
- const uint64_t vrDiv100 = div100(vr);
268
- const uint32_t vrMod100 = ((uint32_t) vr) - 100 * ((uint32_t) vrDiv100);
269
- roundUp = vrMod100 >= 50;
270
- vr = vrDiv100;
271
- vp = vpDiv100;
272
- vm = vmDiv100;
273
- removed += 2;
274
- }
275
- // Loop iterations below (approximately), without optimization above:
276
- // 0: 0.03%, 1: 13.8%, 2: 70.6%, 3: 14.0%, 4: 1.40%, 5: 0.14%, 6+: 0.02%
277
- // Loop iterations below (approximately), with optimization above:
278
- // 0: 70.6%, 1: 27.8%, 2: 1.40%, 3: 0.14%, 4+: 0.02%
279
- for (;;) {
280
- const uint64_t vpDiv10 = div10(vp);
281
- const uint64_t vmDiv10 = div10(vm);
282
- if (vpDiv10 <= vmDiv10) {
283
- break;
284
- }
285
- const uint64_t vrDiv10 = div10(vr);
286
- const uint32_t vrMod10 = ((uint32_t) vr) - 10 * ((uint32_t) vrDiv10);
287
- roundUp = vrMod10 >= 5;
288
- vr = vrDiv10;
289
- vp = vpDiv10;
290
- vm = vmDiv10;
291
- ++removed;
292
- }
293
- #ifdef RYU_DEBUG
294
- printf("%" PRIu64 " roundUp=%s\n", vr, roundUp ? "true" : "false");
295
- printf("vr is trailing zeros=%s\n", vrIsTrailingZeros ? "true" : "false");
296
- #endif
297
- // We need to take vr + 1 if vr is outside bounds or we need to round up.
298
- output = vr + (vr == vm || roundUp);
299
- }
300
- const int32_t exp = e10 + removed;
301
-
302
- #ifdef RYU_DEBUG
303
- printf("V+=%" PRIu64 "\nV =%" PRIu64 "\nV-=%" PRIu64 "\n", vp, vr, vm);
304
- printf("O=%" PRIu64 "\n", output);
305
- printf("EXP=%d\n", exp);
306
- #endif
307
-
308
- floating_decimal_64 fd;
309
- fd.exponent = exp;
310
- fd.mantissa = output;
311
- return fd;
312
- }
313
-
314
- static inline int to_chars(const floating_decimal_64 v, const bool sign, char* const result) {
315
- // Step 5: Print the decimal representation.
316
- int index = 0;
317
- if (sign) {
318
- result[index++] = '-';
319
- }
320
-
321
- uint64_t output = v.mantissa;
322
- const uint32_t olength = decimalLength17(output);
323
-
324
- #ifdef RYU_DEBUG
325
- printf("DIGITS=%" PRIu64 "\n", v.mantissa);
326
- printf("OLEN=%u\n", olength);
327
- printf("EXP=%u\n", v.exponent + olength);
328
- #endif
329
-
330
- // Print the decimal digits.
331
- // The following code is equivalent to:
332
- // for (uint32_t i = 0; i < olength - 1; ++i) {
333
- // const uint32_t c = output % 10; output /= 10;
334
- // result[index + olength - i] = (char) ('0' + c);
335
- // }
336
- // result[index] = '0' + output % 10;
337
-
338
- uint32_t i = 0;
339
- // We prefer 32-bit operations, even on 64-bit platforms.
340
- // We have at most 17 digits, and uint32_t can store 9 digits.
341
- // If output doesn't fit into uint32_t, we cut off 8 digits,
342
- // so the rest will fit into uint32_t.
343
- if ((output >> 32) != 0) {
344
- // Expensive 64-bit division.
345
- const uint64_t q = div1e8(output);
346
- uint32_t output2 = ((uint32_t) output) - 100000000 * ((uint32_t) q);
347
- output = q;
348
-
349
- const uint32_t c = output2 % 10000;
350
- output2 /= 10000;
351
- const uint32_t d = output2 % 10000;
352
- const uint32_t c0 = (c % 100) << 1;
353
- const uint32_t c1 = (c / 100) << 1;
354
- const uint32_t d0 = (d % 100) << 1;
355
- const uint32_t d1 = (d / 100) << 1;
356
- memcpy(result + index + olength - i - 1, DIGIT_TABLE + c0, 2);
357
- memcpy(result + index + olength - i - 3, DIGIT_TABLE + c1, 2);
358
- memcpy(result + index + olength - i - 5, DIGIT_TABLE + d0, 2);
359
- memcpy(result + index + olength - i - 7, DIGIT_TABLE + d1, 2);
360
- i += 8;
361
- }
362
- uint32_t output2 = (uint32_t) output;
363
- while (output2 >= 10000) {
364
- #ifdef __clang__ // https://bugs.llvm.org/show_bug.cgi?id=38217
365
- const uint32_t c = output2 - 10000 * (output2 / 10000);
366
- #else
367
- const uint32_t c = output2 % 10000;
368
- #endif
369
- output2 /= 10000;
370
- const uint32_t c0 = (c % 100) << 1;
371
- const uint32_t c1 = (c / 100) << 1;
372
- memcpy(result + index + olength - i - 1, DIGIT_TABLE + c0, 2);
373
- memcpy(result + index + olength - i - 3, DIGIT_TABLE + c1, 2);
374
- i += 4;
375
- }
376
- if (output2 >= 100) {
377
- const uint32_t c = (output2 % 100) << 1;
378
- output2 /= 100;
379
- memcpy(result + index + olength - i - 1, DIGIT_TABLE + c, 2);
380
- i += 2;
381
- }
382
- if (output2 >= 10) {
383
- const uint32_t c = output2 << 1;
384
- // We can't use memcpy here: the decimal dot goes between these two digits.
385
- result[index + olength - i] = DIGIT_TABLE[c + 1];
386
- result[index] = DIGIT_TABLE[c];
387
- } else {
388
- result[index] = (char) ('0' + output2);
389
- }
390
-
391
- // Print decimal point if needed.
392
- if (olength > 1) {
393
- result[index + 1] = '.';
394
- index += olength + 1;
395
- } else {
396
- ++index;
397
- }
398
-
399
- // Print the exponent.
400
- result[index++] = 'E';
401
- int32_t exp = v.exponent + (int32_t) olength - 1;
402
- if (exp < 0) {
403
- result[index++] = '-';
404
- exp = -exp;
405
- }
406
-
407
- if (exp >= 100) {
408
- const int32_t c = exp % 10;
409
- memcpy(result + index, DIGIT_TABLE + 2 * (exp / 10), 2);
410
- result[index + 2] = (char) ('0' + c);
411
- index += 3;
412
- } else if (exp >= 10) {
413
- memcpy(result + index, DIGIT_TABLE + 2 * exp, 2);
414
- index += 2;
415
- } else {
416
- result[index++] = (char) ('0' + exp);
417
- }
418
-
419
- return index;
420
- }
421
-
422
- static inline bool d2d_small_int(const uint64_t ieeeMantissa, const uint32_t ieeeExponent,
423
- floating_decimal_64* const v) {
424
- const uint64_t m2 = (1ull << DOUBLE_MANTISSA_BITS) | ieeeMantissa;
425
- const int32_t e2 = (int32_t) ieeeExponent - DOUBLE_BIAS - DOUBLE_MANTISSA_BITS;
426
-
427
- if (e2 > 0) {
428
- // f = m2 * 2^e2 >= 2^53 is an integer.
429
- // Ignore this case for now.
430
- return false;
431
- }
432
-
433
- if (e2 < -52) {
434
- // f < 1.
435
- return false;
436
- }
437
-
438
- // Since 2^52 <= m2 < 2^53 and 0 <= -e2 <= 52: 1 <= f = m2 / 2^-e2 < 2^53.
439
- // Test if the lower -e2 bits of the significand are 0, i.e. whether the fraction is 0.
440
- const uint64_t mask = (1ull << -e2) - 1;
441
- const uint64_t fraction = m2 & mask;
442
- if (fraction != 0) {
443
- return false;
444
- }
445
-
446
- // f is an integer in the range [1, 2^53).
447
- // Note: mantissa might contain trailing (decimal) 0's.
448
- // Note: since 2^53 < 10^16, there is no need to adjust decimalLength17().
449
- v->mantissa = m2 >> -e2;
450
- v->exponent = 0;
451
- return true;
452
- }
453
-
454
- int d2s_buffered_n(double f, char* result) {
455
- // Step 1: Decode the floating-point number, and unify normalized and subnormal cases.
456
- const uint64_t bits = double_to_bits(f);
457
-
458
- #ifdef RYU_DEBUG
459
- printf("IN=");
460
- for (int32_t bit = 63; bit >= 0; --bit) {
461
- printf("%d", (int) ((bits >> bit) & 1));
462
- }
463
- printf("\n");
464
- #endif
465
-
466
- // Decode bits into sign, mantissa, and exponent.
467
- const bool ieeeSign = ((bits >> (DOUBLE_MANTISSA_BITS + DOUBLE_EXPONENT_BITS)) & 1) != 0;
468
- const uint64_t ieeeMantissa = bits & ((1ull << DOUBLE_MANTISSA_BITS) - 1);
469
- const uint32_t ieeeExponent = (uint32_t) ((bits >> DOUBLE_MANTISSA_BITS) & ((1u << DOUBLE_EXPONENT_BITS) - 1));
470
- // Case distinction; exit early for the easy cases.
471
- if (ieeeExponent == ((1u << DOUBLE_EXPONENT_BITS) - 1u) || (ieeeExponent == 0 && ieeeMantissa == 0)) {
472
- return copy_special_str(result, ieeeSign, ieeeExponent, ieeeMantissa);
473
- }
474
-
475
- floating_decimal_64 v;
476
- const bool isSmallInt = d2d_small_int(ieeeMantissa, ieeeExponent, &v);
477
- if (isSmallInt) {
478
- // For small integers in the range [1, 2^53), v.mantissa might contain trailing (decimal) zeros.
479
- // For scientific notation we need to move these zeros into the exponent.
480
- // (This is not needed for fixed-point notation, so it might be beneficial to trim
481
- // trailing zeros in to_chars only if needed - once fixed-point notation output is implemented.)
482
- for (;;) {
483
- const uint64_t q = div10(v.mantissa);
484
- const uint32_t r = ((uint32_t) v.mantissa) - 10 * ((uint32_t) q);
485
- if (r != 0) {
486
- break;
487
- }
488
- v.mantissa = q;
489
- ++v.exponent;
490
- }
491
- } else {
492
- v = d2d(ieeeMantissa, ieeeExponent);
493
- }
494
-
495
- return to_chars(v, ieeeSign, result);
496
- }
497
-
498
- void d2s_buffered(double f, char* result) {
499
- const int index = d2s_buffered_n(f, result);
500
-
501
- // Terminate the string.
502
- result[index] = '\0';
503
- }
504
-
505
- char* d2s(double f) {
506
- char* const result = (char*) malloc(25);
507
- d2s_buffered(f, result);
508
- return result;
509
- }