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.
- package/CHANGELOG.md +7 -0
- package/package.json +2 -2
- package/src/cnoke/cnoke.js +3 -7
- package/src/cnoke/src/builder.js +9 -6
- package/src/cnoke/src/index.js +2 -2
- package/src/koffi/build/2.3.7/koffi_darwin_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_darwin_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_freebsd_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_freebsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_freebsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_arm32hf/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_linux_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_openbsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_openbsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_win32_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_win32_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.7/koffi_win32_x64/koffi.node +0 -0
- package/src/koffi/src/ffi.cc +2 -2
- package/src/koffi/src/index.d.ts +2 -2
- package/src/koffi/src/index.js +1 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_darwin_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_darwin_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_freebsd_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_freebsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_freebsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_linux_arm32hf/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_linux_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_linux_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_linux_riscv64hf64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_linux_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_openbsd_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_openbsd_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_win32_arm64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_win32_arm64/koffi.pdb +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_win32_ia32/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_win32_ia32/koffi.pdb +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_win32_x64/koffi.node +0 -0
- package/src/koffi/build/2.3.6-beta.6/koffi_win32_x64/koffi.pdb +0 -0
- package/vendor/brotli/BUILD +0 -144
- package/vendor/brotli/CMakeLists.txt +0 -421
- package/vendor/brotli/CONTRIBUTING.md +0 -27
- package/vendor/brotli/LICENSE +0 -19
- package/vendor/brotli/MANIFEST.in +0 -17
- package/vendor/brotli/Makefile +0 -55
- package/vendor/brotli/Makefile.am +0 -38
- package/vendor/brotli/README +0 -15
- package/vendor/brotli/README.md +0 -104
- package/vendor/brotli/WORKSPACE +0 -21
- package/vendor/brotli/bootstrap +0 -35
- package/vendor/brotli/c/common/constants.c +0 -15
- package/vendor/brotli/c/common/constants.h +0 -200
- package/vendor/brotli/c/common/context.c +0 -156
- package/vendor/brotli/c/common/context.h +0 -113
- package/vendor/brotli/c/common/dictionary.c +0 -5914
- package/vendor/brotli/c/common/dictionary.h +0 -64
- package/vendor/brotli/c/common/platform.c +0 -22
- package/vendor/brotli/c/common/platform.h +0 -596
- package/vendor/brotli/c/common/transform.c +0 -291
- package/vendor/brotli/c/common/transform.h +0 -85
- package/vendor/brotli/c/common/version.h +0 -26
- package/vendor/brotli/c/dec/bit_reader.c +0 -76
- package/vendor/brotli/c/dec/bit_reader.h +0 -351
- package/vendor/brotli/c/dec/decode.c +0 -2608
- package/vendor/brotli/c/dec/huffman.c +0 -339
- package/vendor/brotli/c/dec/huffman.h +0 -121
- package/vendor/brotli/c/dec/prefix.h +0 -732
- package/vendor/brotli/c/dec/state.c +0 -159
- package/vendor/brotli/c/dec/state.h +0 -365
- package/vendor/brotli/c/enc/backward_references.c +0 -145
- package/vendor/brotli/c/enc/backward_references.h +0 -39
- package/vendor/brotli/c/enc/backward_references_hq.c +0 -843
- package/vendor/brotli/c/enc/backward_references_hq.h +0 -95
- package/vendor/brotli/c/enc/backward_references_inc.h +0 -163
- package/vendor/brotli/c/enc/bit_cost.c +0 -35
- package/vendor/brotli/c/enc/bit_cost.h +0 -63
- package/vendor/brotli/c/enc/bit_cost_inc.h +0 -127
- package/vendor/brotli/c/enc/block_encoder_inc.h +0 -34
- package/vendor/brotli/c/enc/block_splitter.c +0 -194
- package/vendor/brotli/c/enc/block_splitter.h +0 -51
- package/vendor/brotli/c/enc/block_splitter_inc.h +0 -440
- package/vendor/brotli/c/enc/brotli_bit_stream.c +0 -1314
- package/vendor/brotli/c/enc/brotli_bit_stream.h +0 -84
- package/vendor/brotli/c/enc/cluster.c +0 -56
- package/vendor/brotli/c/enc/cluster.h +0 -48
- package/vendor/brotli/c/enc/cluster_inc.h +0 -320
- package/vendor/brotli/c/enc/command.c +0 -28
- package/vendor/brotli/c/enc/command.h +0 -190
- package/vendor/brotli/c/enc/compress_fragment.c +0 -790
- package/vendor/brotli/c/enc/compress_fragment.h +0 -61
- package/vendor/brotli/c/enc/compress_fragment_two_pass.c +0 -645
- package/vendor/brotli/c/enc/compress_fragment_two_pass.h +0 -54
- package/vendor/brotli/c/enc/dictionary_hash.c +0 -1846
- package/vendor/brotli/c/enc/dictionary_hash.h +0 -25
- package/vendor/brotli/c/enc/encode.c +0 -1927
- package/vendor/brotli/c/enc/encoder_dict.c +0 -33
- package/vendor/brotli/c/enc/encoder_dict.h +0 -43
- package/vendor/brotli/c/enc/entropy_encode.c +0 -503
- package/vendor/brotli/c/enc/entropy_encode.h +0 -122
- package/vendor/brotli/c/enc/entropy_encode_static.h +0 -539
- package/vendor/brotli/c/enc/fast_log.c +0 -105
- package/vendor/brotli/c/enc/fast_log.h +0 -66
- package/vendor/brotli/c/enc/find_match_length.h +0 -79
- package/vendor/brotli/c/enc/hash.h +0 -488
- package/vendor/brotli/c/enc/hash_composite_inc.h +0 -125
- package/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +0 -293
- package/vendor/brotli/c/enc/hash_longest_match64_inc.h +0 -267
- package/vendor/brotli/c/enc/hash_longest_match_inc.h +0 -262
- package/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +0 -266
- package/vendor/brotli/c/enc/hash_rolling_inc.h +0 -212
- package/vendor/brotli/c/enc/hash_to_binary_tree_inc.h +0 -329
- package/vendor/brotli/c/enc/histogram.c +0 -100
- package/vendor/brotli/c/enc/histogram.h +0 -63
- package/vendor/brotli/c/enc/histogram_inc.h +0 -51
- package/vendor/brotli/c/enc/literal_cost.c +0 -175
- package/vendor/brotli/c/enc/literal_cost.h +0 -30
- package/vendor/brotli/c/enc/memory.c +0 -170
- package/vendor/brotli/c/enc/memory.h +0 -114
- package/vendor/brotli/c/enc/metablock.c +0 -663
- package/vendor/brotli/c/enc/metablock.h +0 -105
- package/vendor/brotli/c/enc/metablock_inc.h +0 -183
- package/vendor/brotli/c/enc/params.h +0 -46
- package/vendor/brotli/c/enc/prefix.h +0 -53
- package/vendor/brotli/c/enc/quality.h +0 -165
- package/vendor/brotli/c/enc/ringbuffer.h +0 -167
- package/vendor/brotli/c/enc/static_dict.c +0 -486
- package/vendor/brotli/c/enc/static_dict.h +0 -40
- package/vendor/brotli/c/enc/static_dict_lut.h +0 -5864
- package/vendor/brotli/c/enc/utf8_util.c +0 -85
- package/vendor/brotli/c/enc/utf8_util.h +0 -32
- package/vendor/brotli/c/enc/write_bits.h +0 -87
- package/vendor/brotli/c/include/brotli/decode.h +0 -344
- package/vendor/brotli/c/include/brotli/encode.h +0 -448
- package/vendor/brotli/c/include/brotli/port.h +0 -288
- package/vendor/brotli/c/include/brotli/types.h +0 -83
- package/vendor/brotli/c/tools/brotli.c +0 -1116
- package/vendor/brotli/c/tools/brotli.md +0 -107
- package/vendor/brotli/compiler_config_setting.bzl +0 -28
- package/vendor/brotli/configure +0 -8
- package/vendor/brotli/configure-cmake +0 -318
- package/vendor/brotli/configure.ac +0 -14
- package/vendor/brotli/docs/brotli.1 +0 -132
- package/vendor/brotli/docs/constants.h.3 +0 -47
- package/vendor/brotli/docs/decode.h.3 +0 -415
- package/vendor/brotli/docs/encode.h.3 +0 -586
- package/vendor/brotli/docs/types.h.3 +0 -117
- package/vendor/brotli/premake5.lua +0 -78
- package/vendor/brotli/python/Makefile +0 -57
- package/vendor/brotli/python/README.md +0 -54
- package/vendor/brotli/python/_brotli.cc +0 -753
- package/vendor/brotli/python/bro.py +0 -160
- package/vendor/brotli/python/brotli.py +0 -56
- package/vendor/brotli/python/tests/__init__.py +0 -0
- package/vendor/brotli/python/tests/_test_utils.py +0 -112
- package/vendor/brotli/python/tests/bro_test.py +0 -102
- package/vendor/brotli/python/tests/compress_test.py +0 -41
- package/vendor/brotli/python/tests/compressor_test.py +0 -94
- package/vendor/brotli/python/tests/decompress_test.py +0 -42
- package/vendor/brotli/python/tests/decompressor_test.py +0 -59
- package/vendor/brotli/scripts/libbrotlicommon.pc.in +0 -11
- package/vendor/brotli/scripts/libbrotlidec.pc.in +0 -12
- package/vendor/brotli/scripts/libbrotlienc.pc.in +0 -12
- package/vendor/brotli/scripts/sources.lst +0 -104
- package/vendor/brotli/setup.cfg +0 -5
- package/vendor/brotli/setup.py +0 -293
- package/vendor/brotli/tests/Makefile +0 -17
- package/vendor/brotli/tests/compatibility_test.sh +0 -25
- package/vendor/brotli/tests/roundtrip_test.sh +0 -36
- package/vendor/brotli/tests/run-compatibility-test.cmake +0 -31
- package/vendor/brotli/tests/run-roundtrip-test.cmake +0 -36
- package/vendor/brotli/tests/testdata/empty +0 -0
- package/vendor/brotli/tests/testdata/empty.compressed +0 -1
- package/vendor/brotli/tests/testdata/ukkonooa +0 -1
- package/vendor/brotli/tests/testdata/ukkonooa.compressed +0 -0
- package/vendor/dragonbox/CMakeLists.txt +0 -123
- package/vendor/dragonbox/LICENSE-Apache2-LLVM +0 -218
- package/vendor/dragonbox/LICENSE-Boost +0 -23
- package/vendor/dragonbox/README.md +0 -277
- package/vendor/dragonbox/cmake/dragonboxConfig.cmake +0 -1
- package/vendor/dragonbox/include/dragonbox/dragonbox.h +0 -2674
- package/vendor/dragonbox/include/dragonbox/dragonbox_to_chars.h +0 -108
- package/vendor/dragonbox/other_files/Dragonbox.pdf +0 -0
- package/vendor/dragonbox/other_files/Dragonbox_old.pdf +0 -0
- package/vendor/dragonbox/other_files/milo_benchmark.png +0 -0
- package/vendor/dragonbox/other_files/unknown_win64_vc2019.html +0 -540
- package/vendor/dragonbox/other_files/unknown_win64_vc2019_randomdigit_time.png +0 -0
- package/vendor/dragonbox/source/dragonbox_to_chars.cpp +0 -303
- package/vendor/dragonbox/subproject/3rdparty/grisu_exact/CMakeLists.txt +0 -24
- package/vendor/dragonbox/subproject/3rdparty/grisu_exact/fp_to_chars.cpp +0 -238
- package/vendor/dragonbox/subproject/3rdparty/grisu_exact/fp_to_chars.h +0 -95
- package/vendor/dragonbox/subproject/3rdparty/grisu_exact/grisu_exact.h +0 -2666
- package/vendor/dragonbox/subproject/3rdparty/ryu/CMakeLists.txt +0 -16
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/common.h +0 -114
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s.c +0 -509
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s_full_table.h +0 -367
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/d2s_intrinsics.h +0 -357
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/digit_table.h +0 -35
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s.c +0 -345
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s_full_table.h +0 -55
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/f2s_intrinsics.h +0 -128
- package/vendor/dragonbox/subproject/3rdparty/ryu/ryu/ryu.h +0 -46
- package/vendor/dragonbox/subproject/3rdparty/schubfach/CMakeLists.txt +0 -22
- package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_32.cc +0 -699
- package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_32.h +0 -31
- package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_64.cc +0 -1354
- package/vendor/dragonbox/subproject/3rdparty/schubfach/schubfach_64.h +0 -31
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/example_shaded_plots.m +0 -68
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/license.txt +0 -25
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_distribution.m +0 -92
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_distribution_prctile.m +0 -121
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_histogram_shaded.m +0 -99
- package/vendor/dragonbox/subproject/3rdparty/shaded_plots/plot_shaded.m +0 -93
- package/vendor/dragonbox/subproject/benchmark/CMakeLists.txt +0 -65
- package/vendor/dragonbox/subproject/benchmark/include/benchmark.h +0 -40
- package/vendor/dragonbox/subproject/benchmark/matlab/plot_benchmarks.m +0 -22
- package/vendor/dragonbox/subproject/benchmark/matlab/plot_digit_benchmark.m +0 -78
- package/vendor/dragonbox/subproject/benchmark/matlab/plot_uniform_benchmark.m +0 -95
- package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary32_clang.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary32_msvc.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary64_clang.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/digits_benchmark_binary64_msvc.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary32_clang.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary32_msvc.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary64_clang.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/results/uniform_benchmark_binary64_msvc.png +0 -0
- package/vendor/dragonbox/subproject/benchmark/source/benchmark.cpp +0 -238
- package/vendor/dragonbox/subproject/benchmark/source/dragonbox.cpp +0 -30
- package/vendor/dragonbox/subproject/benchmark/source/grisu_exact.cpp +0 -36
- package/vendor/dragonbox/subproject/benchmark/source/ryu.cpp +0 -27
- package/vendor/dragonbox/subproject/benchmark/source/schubfach.cpp +0 -31
- package/vendor/dragonbox/subproject/common/CMakeLists.txt +0 -42
- package/vendor/dragonbox/subproject/common/include/best_rational_approx.h +0 -97
- package/vendor/dragonbox/subproject/common/include/big_uint.h +0 -218
- package/vendor/dragonbox/subproject/common/include/continued_fractions.h +0 -174
- package/vendor/dragonbox/subproject/common/include/good_rational_approx.h +0 -267
- package/vendor/dragonbox/subproject/common/include/random_float.h +0 -182
- package/vendor/dragonbox/subproject/common/include/rational_continued_fractions.h +0 -57
- package/vendor/dragonbox/subproject/common/source/big_uint.cpp +0 -602
- package/vendor/dragonbox/subproject/meta/CMakeLists.txt +0 -41
- package/vendor/dragonbox/subproject/meta/results/binary32_generated_cache.txt +0 -82
- package/vendor/dragonbox/subproject/meta/results/binary64_compressed_cache_error_table.txt +0 -10
- package/vendor/dragonbox/subproject/meta/results/binary64_generated_cache.txt +0 -623
- package/vendor/dragonbox/subproject/meta/source/generate_cache.cpp +0 -126
- package/vendor/dragonbox/subproject/meta/source/live_test.cpp +0 -81
- package/vendor/dragonbox/subproject/meta/source/perf_test.cpp +0 -104
- package/vendor/dragonbox/subproject/meta/source/sandbox.cpp +0 -20
- package/vendor/dragonbox/subproject/test/CMakeLists.txt +0 -70
- package/vendor/dragonbox/subproject/test/results/binary32.csv +0 -255
- package/vendor/dragonbox/subproject/test/results/binary64.csv +0 -2047
- package/vendor/dragonbox/subproject/test/results/plot_required_bits.m +0 -18
- package/vendor/dragonbox/subproject/test/source/test_all_shorter_interval_cases.cpp +0 -88
- package/vendor/dragonbox/subproject/test/source/uniform_random_test.cpp +0 -95
- package/vendor/dragonbox/subproject/test/source/verify_cache_precision.cpp +0 -338
- package/vendor/dragonbox/subproject/test/source/verify_compressed_cache.cpp +0 -154
- package/vendor/dragonbox/subproject/test/source/verify_fast_multiplication.cpp +0 -168
- package/vendor/dragonbox/subproject/test/source/verify_log_computation.cpp +0 -251
- package/vendor/dragonbox/subproject/test/source/verify_magic_division.cpp +0 -113
- package/vendor/miniz/ChangeLog.md +0 -239
- package/vendor/miniz/LICENSE +0 -22
- package/vendor/miniz/examples/example1.c +0 -105
- package/vendor/miniz/examples/example2.c +0 -164
- package/vendor/miniz/examples/example3.c +0 -269
- package/vendor/miniz/examples/example4.c +0 -102
- package/vendor/miniz/examples/example5.c +0 -327
- package/vendor/miniz/examples/example6.c +0 -166
- package/vendor/miniz/miniz.c +0 -7835
- package/vendor/miniz/miniz.h +0 -1422
- package/vendor/miniz/readme.md +0 -46
- /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_arm64/koffi.exp +0 -0
- /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_arm64/koffi.lib +0 -0
- /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_ia32/koffi.exp +0 -0
- /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_ia32/koffi.lib +0 -0
- /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_x64/koffi.exp +0 -0
- /package/src/koffi/build/{2.3.6-beta.6 → 2.3.7}/koffi_win32_x64/koffi.lib +0 -0
|
@@ -1,602 +0,0 @@
|
|
|
1
|
-
// Copyright 2022 Junekey Jeon
|
|
2
|
-
//
|
|
3
|
-
// The contents of this file may be used under the terms of
|
|
4
|
-
// the Apache License v2.0 with LLVM Exceptions.
|
|
5
|
-
//
|
|
6
|
-
// (See accompanying file LICENSE-Apache or copy at
|
|
7
|
-
// https://llvm.org/foundation/relicensing/LICENSE.txt)
|
|
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
|
-
#include "big_uint.h"
|
|
19
|
-
#include "dragonbox/dragonbox.h"
|
|
20
|
-
#include <cassert>
|
|
21
|
-
#include <limits>
|
|
22
|
-
|
|
23
|
-
namespace jkj {
|
|
24
|
-
static constexpr std::size_t log2p1(std::uint64_t x) noexcept {
|
|
25
|
-
// C++20 std::log2p1 is not yet supported
|
|
26
|
-
// return std::log2p1(x);
|
|
27
|
-
|
|
28
|
-
std::size_t ret = 0;
|
|
29
|
-
auto inspect = [&x, &ret](int shft) {
|
|
30
|
-
if ((x >> shft) != 0) {
|
|
31
|
-
x >>= shft;
|
|
32
|
-
ret += shft;
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
inspect(32);
|
|
37
|
-
inspect(16);
|
|
38
|
-
inspect(8);
|
|
39
|
-
inspect(4);
|
|
40
|
-
inspect(2);
|
|
41
|
-
inspect(1);
|
|
42
|
-
|
|
43
|
-
return ret + x;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
std::size_t log2p1(big_uint const& n) noexcept {
|
|
47
|
-
if (n.is_zero()) {
|
|
48
|
-
return 0;
|
|
49
|
-
}
|
|
50
|
-
return (n.elements.size() - 1) * big_uint::element_number_of_bits +
|
|
51
|
-
log2p1(n.elements.back());
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
big_uint big_uint::power_of_2(std::size_t k) {
|
|
55
|
-
auto number_of_elmts = k / element_number_of_bits + 1;
|
|
56
|
-
big_uint ret_val;
|
|
57
|
-
ret_val.elements.resize(number_of_elmts, 0);
|
|
58
|
-
ret_val.elements.back() = (element_type(1) << (k % element_number_of_bits));
|
|
59
|
-
return ret_val;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
big_uint big_uint::pow(big_uint base, std::size_t k) {
|
|
63
|
-
big_uint result{1};
|
|
64
|
-
while (true) {
|
|
65
|
-
if (k % 2 != 0) {
|
|
66
|
-
result *= base;
|
|
67
|
-
}
|
|
68
|
-
k /= 2;
|
|
69
|
-
if (k == 0) {
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
base *= base;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
std::size_t big_uint::multiply_2_until(big_uint const& n) {
|
|
79
|
-
assert(elements.size() != 0);
|
|
80
|
-
|
|
81
|
-
std::size_t number_of_multiplications = 0;
|
|
82
|
-
|
|
83
|
-
// Perform left-shift to match the leading-1 position.
|
|
84
|
-
// Perform element-wise shift first.
|
|
85
|
-
assert(elements.size() <= n.elements.size());
|
|
86
|
-
auto element_pos_offset = n.elements.size() - elements.size();
|
|
87
|
-
if (element_pos_offset > 0) {
|
|
88
|
-
number_of_multiplications = element_pos_offset * element_number_of_bits;
|
|
89
|
-
auto old_size = elements.size();
|
|
90
|
-
elements.resize(n.elements.size());
|
|
91
|
-
|
|
92
|
-
std::move_backward(std::begin(elements), std::begin(elements) + old_size,
|
|
93
|
-
std::begin(elements) + elements.size());
|
|
94
|
-
|
|
95
|
-
std::fill_n(std::begin(elements), element_pos_offset, 0);
|
|
96
|
-
}
|
|
97
|
-
// And then perform bit-wise shift.
|
|
98
|
-
auto new_bit_pos = log2p1(elements.back());
|
|
99
|
-
auto bit_pos_offset =
|
|
100
|
-
std::ptrdiff_t(log2p1(n.elements.back())) - std::ptrdiff_t(new_bit_pos);
|
|
101
|
-
assert(element_pos_offset > 0 || (element_pos_offset == 0 && bit_pos_offset >= 0));
|
|
102
|
-
number_of_multiplications += bit_pos_offset;
|
|
103
|
-
if (bit_pos_offset > 0) {
|
|
104
|
-
// Left-shfit
|
|
105
|
-
auto shft = std::size_t(bit_pos_offset);
|
|
106
|
-
auto remaining_bits = element_number_of_bits - shft;
|
|
107
|
-
for (auto idx = elements.size() - 1; idx > 0; --idx) {
|
|
108
|
-
auto bits_to_transfer = elements[idx - 1] >> remaining_bits;
|
|
109
|
-
|
|
110
|
-
elements[idx] <<= shft;
|
|
111
|
-
elements[idx] |= bits_to_transfer;
|
|
112
|
-
}
|
|
113
|
-
elements[0] <<= shft;
|
|
114
|
-
}
|
|
115
|
-
else if (bit_pos_offset < 0) {
|
|
116
|
-
// Right-shift
|
|
117
|
-
auto shft = std::size_t(-bit_pos_offset);
|
|
118
|
-
auto remaining_bits = element_number_of_bits - shft;
|
|
119
|
-
elements[0] >>= shft;
|
|
120
|
-
for (std::size_t idx = 1; idx < elements.size(); ++idx) {
|
|
121
|
-
auto bits_to_transfer = elements[idx] << remaining_bits;
|
|
122
|
-
|
|
123
|
-
elements[idx - 1] |= bits_to_transfer;
|
|
124
|
-
elements[idx] >>= shft;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
// Compare the shifted number with the given number.
|
|
129
|
-
bool is_bigger_than_or_equal_to = true;
|
|
130
|
-
for (auto idx = std::ptrdiff_t(elements.size()) - 1; idx >= 0; --idx) {
|
|
131
|
-
if (elements[idx] > n.elements[idx])
|
|
132
|
-
break;
|
|
133
|
-
else if (elements[idx] < n.elements[idx]) {
|
|
134
|
-
is_bigger_than_or_equal_to = false;
|
|
135
|
-
break;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// If our number is still less,
|
|
140
|
-
if (!is_bigger_than_or_equal_to) {
|
|
141
|
-
// Shift one more bit.
|
|
142
|
-
++number_of_multiplications;
|
|
143
|
-
if (new_bit_pos == element_number_of_bits) {
|
|
144
|
-
elements.resize(elements.size() + 1);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
constexpr auto remaining_bits = element_number_of_bits - 1;
|
|
148
|
-
for (auto idx = elements.size() - 1; idx > 0; --idx) {
|
|
149
|
-
elements[idx] <<= 1;
|
|
150
|
-
elements[idx] |= (elements[idx - 1] >> remaining_bits);
|
|
151
|
-
}
|
|
152
|
-
elements[0] <<= 1;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return number_of_multiplications;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
std::size_t big_uint::multiply_2_while(big_uint const& n) {
|
|
159
|
-
assert(elements.size() != 0);
|
|
160
|
-
|
|
161
|
-
std::size_t number_of_multiplications = 0;
|
|
162
|
-
|
|
163
|
-
// Perform left-shift to match the leading-1 position.
|
|
164
|
-
// Perform element-wise shift first.
|
|
165
|
-
assert(elements.size() <= n.elements.size());
|
|
166
|
-
auto element_pos_offset = n.elements.size() - elements.size();
|
|
167
|
-
if (element_pos_offset > 0) {
|
|
168
|
-
number_of_multiplications = element_pos_offset * element_number_of_bits;
|
|
169
|
-
auto old_size = elements.size();
|
|
170
|
-
elements.resize(n.elements.size());
|
|
171
|
-
|
|
172
|
-
std::move_backward(std::begin(elements), std::begin(elements) + old_size,
|
|
173
|
-
std::begin(elements) + elements.size());
|
|
174
|
-
|
|
175
|
-
std::fill_n(std::begin(elements), element_pos_offset, 0);
|
|
176
|
-
}
|
|
177
|
-
// And then perform bit-wise shift.
|
|
178
|
-
auto new_bit_pos = log2p1(elements.back());
|
|
179
|
-
auto bit_pos_offset =
|
|
180
|
-
std::ptrdiff_t(log2p1(n.elements.back())) - std::ptrdiff_t(new_bit_pos);
|
|
181
|
-
assert(element_pos_offset > 0 || (element_pos_offset == 0 && bit_pos_offset >= 0));
|
|
182
|
-
number_of_multiplications += bit_pos_offset;
|
|
183
|
-
if (bit_pos_offset > 0) {
|
|
184
|
-
// Left-shfit
|
|
185
|
-
auto shft = std::size_t(bit_pos_offset);
|
|
186
|
-
auto remaining_bits = element_number_of_bits - shft;
|
|
187
|
-
for (auto idx = elements.size() - 1; idx > 0; --idx) {
|
|
188
|
-
auto bits_to_transfer = elements[idx - 1] >> remaining_bits;
|
|
189
|
-
|
|
190
|
-
elements[idx] <<= shft;
|
|
191
|
-
elements[idx] |= bits_to_transfer;
|
|
192
|
-
}
|
|
193
|
-
elements[0] <<= shft;
|
|
194
|
-
}
|
|
195
|
-
else if (bit_pos_offset < 0) {
|
|
196
|
-
// Right-shift
|
|
197
|
-
auto shft = std::size_t(-bit_pos_offset);
|
|
198
|
-
auto remaining_bits = element_number_of_bits - shft;
|
|
199
|
-
elements[0] >>= shft;
|
|
200
|
-
for (std::size_t idx = 1; idx < elements.size(); ++idx) {
|
|
201
|
-
auto bits_to_transfer = elements[idx] << remaining_bits;
|
|
202
|
-
|
|
203
|
-
elements[idx - 1] |= bits_to_transfer;
|
|
204
|
-
elements[idx] >>= shft;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
// Compare the shifted number with the given number.
|
|
209
|
-
bool is_strictly_bigger = true;
|
|
210
|
-
for (auto idx = std::ptrdiff_t(elements.size()) - 1; idx >= 0; --idx) {
|
|
211
|
-
if (elements[idx] > n.elements[idx])
|
|
212
|
-
break;
|
|
213
|
-
else if (elements[idx] <= n.elements[idx]) {
|
|
214
|
-
is_strictly_bigger = false;
|
|
215
|
-
break;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// If our number is strictly bigger,
|
|
220
|
-
if (is_strictly_bigger) {
|
|
221
|
-
// Shift one bit back.
|
|
222
|
-
assert(number_of_multiplications > 0);
|
|
223
|
-
--number_of_multiplications;
|
|
224
|
-
|
|
225
|
-
constexpr auto remaining_bits = element_number_of_bits - 1;
|
|
226
|
-
for (auto idx = 0; idx < elements.size() - 1; ++idx) {
|
|
227
|
-
elements[idx] >>= 1;
|
|
228
|
-
elements[idx] |= (elements[idx + 1] << remaining_bits);
|
|
229
|
-
}
|
|
230
|
-
elements.back() >>= 1;
|
|
231
|
-
|
|
232
|
-
if (elements.back() == 0) {
|
|
233
|
-
elements.pop_back();
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return number_of_multiplications;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
void big_uint::multiply_2() & {
|
|
241
|
-
// Shift to left by 1.
|
|
242
|
-
element_type carry = 0;
|
|
243
|
-
for (std::size_t idx = 0; idx < elements.size(); ++idx) {
|
|
244
|
-
auto new_element = (elements[idx] << 1) | carry;
|
|
245
|
-
|
|
246
|
-
// Keep the carry.
|
|
247
|
-
carry = (elements[idx] >> (element_number_of_bits - 1));
|
|
248
|
-
|
|
249
|
-
elements[idx] = new_element;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (carry != 0) {
|
|
253
|
-
elements.push_back(1);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
void big_uint::multiply_5() & {
|
|
258
|
-
if (elements.size() == 0) {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
element_type upper_2_bits = 0;
|
|
263
|
-
element_type carry = 0;
|
|
264
|
-
for (std::size_t idx = 0; idx < elements.size(); ++idx) {
|
|
265
|
-
auto times_4 = (elements[idx] << 2) | upper_2_bits;
|
|
266
|
-
upper_2_bits = (elements[idx] >> (element_number_of_bits - 2));
|
|
267
|
-
|
|
268
|
-
element_type new_carry = 0;
|
|
269
|
-
// Add *this with *this * 4.
|
|
270
|
-
elements[idx] += times_4;
|
|
271
|
-
// If carry happens,
|
|
272
|
-
if (elements[idx] < times_4) {
|
|
273
|
-
new_carry = 1;
|
|
274
|
-
// Add the carry from the previous element.
|
|
275
|
-
elements[idx] += carry;
|
|
276
|
-
}
|
|
277
|
-
// If no carry happens,
|
|
278
|
-
else {
|
|
279
|
-
// Add the carry from the previous element.
|
|
280
|
-
elements[idx] += carry;
|
|
281
|
-
// If carry happens,
|
|
282
|
-
if (elements[idx] < carry) {
|
|
283
|
-
new_carry = 1;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
carry = new_carry;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
upper_2_bits += carry;
|
|
290
|
-
if (upper_2_bits != 0) {
|
|
291
|
-
elements.push_back(upper_2_bits);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
int big_uint::comparison_common(big_uint const& n) const noexcept {
|
|
296
|
-
if (elements.size() < n.elements.size()) {
|
|
297
|
-
return -1;
|
|
298
|
-
}
|
|
299
|
-
else if (elements.size() > n.elements.size()) {
|
|
300
|
-
return +1;
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
for (auto idx_p1 = elements.size(); idx_p1 > 0; --idx_p1) {
|
|
304
|
-
if (elements[idx_p1 - 1] < n.elements[idx_p1 - 1]) {
|
|
305
|
-
return -1;
|
|
306
|
-
}
|
|
307
|
-
else if (elements[idx_p1 - 1] > n.elements[idx_p1 - 1]) {
|
|
308
|
-
return +1;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return 0;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
big_uint& big_uint::operator+=(big_uint const& n) & {
|
|
316
|
-
std::size_t min_size;
|
|
317
|
-
if (elements.size() >= n.elements.size()) {
|
|
318
|
-
min_size = n.elements.size();
|
|
319
|
-
}
|
|
320
|
-
else {
|
|
321
|
-
min_size = elements.size();
|
|
322
|
-
elements.insert(elements.cend(), n.elements.cbegin() + min_size, n.elements.cend());
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
unsigned int carry = 0;
|
|
326
|
-
for (std::size_t idx = 0; idx < min_size; ++idx) {
|
|
327
|
-
auto with_carry = elements[idx] + carry;
|
|
328
|
-
unsigned int first_carry = (with_carry < elements[idx]) ? 1 : 0;
|
|
329
|
-
|
|
330
|
-
auto n_element = n.elements[idx];
|
|
331
|
-
elements[idx] = with_carry + n_element;
|
|
332
|
-
carry = first_carry | ((elements[idx] < n_element) ? 1 : 0);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
if (carry != 0) {
|
|
336
|
-
for (std::size_t idx = min_size; idx < elements.size(); ++idx) {
|
|
337
|
-
++elements[idx];
|
|
338
|
-
if (elements[idx] != 0) {
|
|
339
|
-
return *this;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
elements.push_back(1);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
return *this;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
big_uint& big_uint::operator+=(element_type n) & {
|
|
349
|
-
if (is_zero()) {
|
|
350
|
-
elements.push_back(n);
|
|
351
|
-
return *this;
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
elements[0] += n;
|
|
355
|
-
|
|
356
|
-
// If carry happens,
|
|
357
|
-
if (elements[0] < n) {
|
|
358
|
-
// Propagate carry.
|
|
359
|
-
for (std::size_t idx = 1; idx < elements.size(); ++idx) {
|
|
360
|
-
++elements[idx];
|
|
361
|
-
if (elements[idx] != 0) {
|
|
362
|
-
return *this;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
elements.push_back(1);
|
|
366
|
-
}
|
|
367
|
-
return *this;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
big_uint& big_uint::operator-=(big_uint const& n) & {
|
|
371
|
-
// Underflow!
|
|
372
|
-
assert(elements.size() >= n.elements.size());
|
|
373
|
-
|
|
374
|
-
unsigned int borrow = 0;
|
|
375
|
-
for (std::size_t idx = 0; idx < n.elements.size(); ++idx) {
|
|
376
|
-
auto with_borrow = elements[idx] - borrow;
|
|
377
|
-
unsigned int first_borrow = (with_borrow > elements[idx]) ? 1 : 0;
|
|
378
|
-
|
|
379
|
-
auto n_element = n.elements[idx];
|
|
380
|
-
elements[idx] = with_borrow - n_element;
|
|
381
|
-
borrow = first_borrow | ((elements[idx] > with_borrow) ? 1 : 0);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
if (borrow != 0) {
|
|
385
|
-
for (std::size_t idx = n.elements.size(); idx < elements.size(); ++idx) {
|
|
386
|
-
--elements[idx];
|
|
387
|
-
if (elements[idx] != std::numeric_limits<element_type>::max()) {
|
|
388
|
-
goto remove_leading_zeros;
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
// Underflow!
|
|
392
|
-
assert(elements.back() != std::numeric_limits<element_type>::max());
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
remove_leading_zeros:
|
|
396
|
-
auto itr = elements.end();
|
|
397
|
-
for (; itr != elements.begin(); --itr) {
|
|
398
|
-
if (*(itr - 1) != 0) {
|
|
399
|
-
break;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
elements.erase(itr, elements.end());
|
|
403
|
-
|
|
404
|
-
return *this;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
big_uint& big_uint::operator--() & {
|
|
408
|
-
// Underflow!
|
|
409
|
-
assert(!is_zero());
|
|
410
|
-
|
|
411
|
-
for (std::size_t idx = 0; idx < elements.size(); ++idx) {
|
|
412
|
-
--elements[idx];
|
|
413
|
-
if (elements[idx] != std::numeric_limits<element_type>::max()) {
|
|
414
|
-
break;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
// Remove leading zeros
|
|
419
|
-
auto itr = elements.end();
|
|
420
|
-
for (; itr != elements.begin(); --itr) {
|
|
421
|
-
if (*(itr - 1) != 0) {
|
|
422
|
-
break;
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
elements.erase(itr, elements.end());
|
|
426
|
-
|
|
427
|
-
return *this;
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
big_uint& big_uint::operator*=(element_type n) & {
|
|
431
|
-
if (n == 0) {
|
|
432
|
-
elements.clear();
|
|
433
|
-
return *this;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
element_type carry = 0;
|
|
437
|
-
for (std::size_t idx = 0; idx < elements.size(); ++idx) {
|
|
438
|
-
auto mul = jkj::dragonbox::detail::wuint::umul128(elements[idx], n);
|
|
439
|
-
elements[idx] = mul.low() + carry;
|
|
440
|
-
carry = mul.high() + (elements[idx] < mul.low() ? 1 : 0);
|
|
441
|
-
}
|
|
442
|
-
if (carry != 0) {
|
|
443
|
-
elements.push_back(carry);
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
return *this;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
big_uint operator*(big_uint const& x, big_uint const& y) {
|
|
450
|
-
if (x.is_zero() || y.is_zero()) {
|
|
451
|
-
return big_uint();
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
big_uint result;
|
|
455
|
-
result.elements.resize(x.elements.size() + y.elements.size(), 0);
|
|
456
|
-
decltype(x.elements) temp(x.elements.size());
|
|
457
|
-
|
|
458
|
-
for (std::size_t y_idx = 0; y_idx < y.elements.size(); ++y_idx) {
|
|
459
|
-
// Compute y.elements[y_idx] * x and accumulate it into the result
|
|
460
|
-
for (std::size_t x_idx = 0; x_idx < x.elements.size(); ++x_idx) {
|
|
461
|
-
auto mul = jkj::dragonbox::detail::wuint::umul128(x.elements[x_idx], y.elements[y_idx]);
|
|
462
|
-
|
|
463
|
-
// Add the first half
|
|
464
|
-
result.elements[x_idx + y_idx] += mul.low();
|
|
465
|
-
unsigned int carry = result.elements[x_idx + y_idx] < mul.low() ? 1 : 0;
|
|
466
|
-
|
|
467
|
-
// Add the second half
|
|
468
|
-
auto with_carry = mul.high() + carry;
|
|
469
|
-
carry = with_carry < mul.high() ? 1 : 0;
|
|
470
|
-
result.elements[x_idx + y_idx + 1] += with_carry;
|
|
471
|
-
|
|
472
|
-
// If there is carry,
|
|
473
|
-
if (result.elements[x_idx + y_idx + 1] < with_carry) {
|
|
474
|
-
// Propagate.
|
|
475
|
-
assert(x_idx + y_idx + 2 < result.elements.size());
|
|
476
|
-
for (auto idx = x_idx + y_idx + 2; idx < result.elements.size(); ++idx) {
|
|
477
|
-
++result.elements[idx];
|
|
478
|
-
if (result.elements[idx] != 0) {
|
|
479
|
-
break;
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
// Remove the last element if it is zero.
|
|
487
|
-
if (result.elements.back() == 0) {
|
|
488
|
-
result.elements.pop_back();
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
return result;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
big_uint big_uint::long_division(big_uint const& n) {
|
|
495
|
-
assert(!n.is_zero());
|
|
496
|
-
|
|
497
|
-
if (this == &n) {
|
|
498
|
-
elements.clear();
|
|
499
|
-
return big_uint(1);
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
big_uint quotient;
|
|
503
|
-
big_uint n_shifted;
|
|
504
|
-
|
|
505
|
-
while (true) {
|
|
506
|
-
// Break if *this is smaller than n.
|
|
507
|
-
if (elements.size() < n.elements.size()) {
|
|
508
|
-
break;
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
// Shift n element-wise first.
|
|
512
|
-
n_shifted.elements.resize(elements.size());
|
|
513
|
-
std::fill_n(n_shifted.elements.begin(), (elements.size() - n.elements.size()), 0);
|
|
514
|
-
std::copy(n.elements.cbegin(), n.elements.cend(),
|
|
515
|
-
n_shifted.elements.begin() + (elements.size() - n.elements.size()));
|
|
516
|
-
|
|
517
|
-
std::size_t total_shift_amount =
|
|
518
|
-
element_number_of_bits * (elements.size() - n.elements.size());
|
|
519
|
-
|
|
520
|
-
// Shift n bit-wise to match the leading 1 position.
|
|
521
|
-
auto leading_1_pos = log2p1(elements.back());
|
|
522
|
-
auto n_leading_1_pos = log2p1(n_shifted.elements.back());
|
|
523
|
-
|
|
524
|
-
if (leading_1_pos > n_leading_1_pos) {
|
|
525
|
-
// Shift left.
|
|
526
|
-
auto shift_amount = leading_1_pos - n_leading_1_pos;
|
|
527
|
-
total_shift_amount += shift_amount;
|
|
528
|
-
|
|
529
|
-
element_type carry = 0;
|
|
530
|
-
for (std::size_t idx = elements.size() - n.elements.size(); idx < elements.size();
|
|
531
|
-
++idx) {
|
|
532
|
-
auto new_element = (n_shifted.elements[idx] << shift_amount) | carry;
|
|
533
|
-
carry = (n_shifted.elements[idx] >> (element_number_of_bits - shift_amount));
|
|
534
|
-
n_shifted.elements[idx] = new_element;
|
|
535
|
-
}
|
|
536
|
-
assert(carry == 0);
|
|
537
|
-
}
|
|
538
|
-
else if (leading_1_pos < n_leading_1_pos) {
|
|
539
|
-
// Break if *this is smaller than n.
|
|
540
|
-
if (total_shift_amount == 0) {
|
|
541
|
-
break;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
// Shift right.
|
|
545
|
-
auto shift_amount = n_leading_1_pos - leading_1_pos;
|
|
546
|
-
assert(total_shift_amount > shift_amount);
|
|
547
|
-
total_shift_amount -= shift_amount;
|
|
548
|
-
for (std::size_t idx = elements.size() - n.elements.size(); idx < elements.size();
|
|
549
|
-
++idx) {
|
|
550
|
-
n_shifted.elements[idx - 1] |=
|
|
551
|
-
(n_shifted.elements[idx] << (element_number_of_bits - shift_amount));
|
|
552
|
-
n_shifted.elements[idx] >>= shift_amount;
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
// Check if n_shifted is bigger than *this; if that's the case, shift one bit to right.
|
|
557
|
-
if (n_shifted > *this) {
|
|
558
|
-
// If we actually didn't shift anything,
|
|
559
|
-
if (total_shift_amount == 0) {
|
|
560
|
-
// *this is smaller than n.
|
|
561
|
-
break;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
// Shift right.
|
|
565
|
-
--total_shift_amount;
|
|
566
|
-
n_shifted.elements[0] >>= 1;
|
|
567
|
-
for (std::size_t idx = 1; idx < elements.size(); ++idx) {
|
|
568
|
-
n_shifted.elements[idx - 1] |=
|
|
569
|
-
(n_shifted.elements[idx] << (element_number_of_bits - 1));
|
|
570
|
-
n_shifted.elements[idx] >>= 1;
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
// Subtract n_shifted from *this.
|
|
575
|
-
*this -= n_shifted;
|
|
576
|
-
|
|
577
|
-
// Update the quotient.
|
|
578
|
-
auto quotient_element_idx = total_shift_amount / element_number_of_bits;
|
|
579
|
-
auto quotient_bit_idx = total_shift_amount % element_number_of_bits;
|
|
580
|
-
if (quotient.elements.size() <= quotient_element_idx) {
|
|
581
|
-
quotient.elements.resize(quotient_element_idx + 1);
|
|
582
|
-
}
|
|
583
|
-
quotient.elements[quotient_element_idx] |= (element_type(1) << quotient_bit_idx);
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
return quotient;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
std::vector<std::uint64_t> big_uint::to_decimal() const {
|
|
590
|
-
std::vector<std::uint64_t> ret;
|
|
591
|
-
auto n = *this;
|
|
592
|
-
auto divisor = big_uint{1000'0000'0000'0000'0000};
|
|
593
|
-
|
|
594
|
-
do {
|
|
595
|
-
auto quotient = n.long_division(divisor);
|
|
596
|
-
ret.push_back(n.is_zero() ? 0 : n[0]);
|
|
597
|
-
n = quotient;
|
|
598
|
-
} while (!n.is_zero());
|
|
599
|
-
|
|
600
|
-
return ret;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
|
2
|
-
|
|
3
|
-
project(dragonbox_meta LANGUAGES CXX)
|
|
4
|
-
|
|
5
|
-
include(FetchContent)
|
|
6
|
-
if (NOT TARGET dragonbox)
|
|
7
|
-
FetchContent_Declare(dragonbox SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../..")
|
|
8
|
-
FetchContent_MakeAvailable(dragonbox)
|
|
9
|
-
endif()
|
|
10
|
-
if (NOT TARGET common)
|
|
11
|
-
FetchContent_Declare(common SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../common")
|
|
12
|
-
FetchContent_MakeAvailable(common)
|
|
13
|
-
endif()
|
|
14
|
-
|
|
15
|
-
function(meta_exe NAME)
|
|
16
|
-
add_executable(${NAME} source/${NAME}.cpp)
|
|
17
|
-
|
|
18
|
-
target_compile_features(${NAME} PRIVATE cxx_std_17)
|
|
19
|
-
|
|
20
|
-
target_link_libraries(${NAME} PRIVATE ${ARGN})
|
|
21
|
-
|
|
22
|
-
# ---- MSVC Specifics ----
|
|
23
|
-
if (MSVC)
|
|
24
|
-
# No need to not generate PDB
|
|
25
|
-
# /permissive- should be the default
|
|
26
|
-
# The compilation will fail without /experimental:newLambdaProcessor
|
|
27
|
-
# See also https://gitlab.kitware.com/cmake/cmake/-/issues/16478
|
|
28
|
-
target_compile_options(${NAME} PUBLIC
|
|
29
|
-
/Zi /permissive-
|
|
30
|
-
$<$<NOT:$<CXX_COMPILER_ID:Clang>>:/experimental:newLambdaProcessor>
|
|
31
|
-
$<$<CONFIG:Release>:/GL>)
|
|
32
|
-
target_link_options(${NAME} PUBLIC /LTCG /DEBUG:FASTLINK)
|
|
33
|
-
set_target_properties(${NAME} PROPERTIES
|
|
34
|
-
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}")
|
|
35
|
-
endif()
|
|
36
|
-
endfunction()
|
|
37
|
-
|
|
38
|
-
meta_exe(generate_cache dragonbox::common)
|
|
39
|
-
meta_exe(live_test dragonbox::dragonbox_to_chars)
|
|
40
|
-
meta_exe(perf_test dragonbox::common dragonbox::dragonbox_to_chars)
|
|
41
|
-
meta_exe(sandbox dragonbox::dragonbox_to_chars dragonbox::common)
|