locutus 2.0.31 → 2.0.34
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/README.md +84 -0
- package/_data/rosetta.yml +325 -0
- package/awk/builtin/index.js +3 -0
- package/awk/builtin/int.js +13 -0
- package/awk/builtin/length.js +16 -0
- package/awk/builtin/substr.js +23 -0
- package/c/ctype/index.js +8 -0
- package/c/ctype/isalnum.js +15 -0
- package/c/ctype/isalpha.js +17 -0
- package/c/ctype/isdigit.js +15 -0
- package/c/ctype/islower.js +15 -0
- package/c/ctype/isspace.js +15 -0
- package/c/ctype/isupper.js +15 -0
- package/c/ctype/tolower.js +15 -0
- package/c/ctype/toupper.js +15 -0
- package/c/index.js +2 -5
- package/c/math/abs.js +14 -18
- package/c/math/frexp.js +19 -20
- package/c/math/index.js +2 -5
- package/c/stdio/index.js +1 -4
- package/c/stdio/sprintf.js +71 -81
- package/c/stdlib/atof.js +15 -0
- package/c/stdlib/atoi.js +17 -0
- package/c/stdlib/index.js +2 -0
- package/c/string/index.js +5 -0
- package/c/string/strcat.js +12 -0
- package/c/string/strchr.js +15 -0
- package/c/string/strcmp.js +21 -0
- package/c/string/strlen.js +12 -0
- package/c/string/strstr.js +15 -0
- package/clojure/Math/abs.js +13 -0
- package/clojure/Math/ceil.js +15 -0
- package/clojure/Math/floor.js +14 -0
- package/clojure/Math/index.js +3 -0
- package/elixir/Float/ceil.js +16 -0
- package/elixir/Float/floor.js +14 -0
- package/elixir/Float/index.js +2 -0
- package/elixir/Kernel/abs.js +13 -0
- package/elixir/Kernel/index.js +1 -0
- package/golang/index.js +1 -4
- package/golang/strconv/Atoi.js +26 -0
- package/golang/strconv/FormatBool.js +12 -0
- package/golang/strconv/FormatInt.js +21 -0
- package/golang/strconv/Itoa.js +14 -0
- package/golang/strconv/ParseBool.js +35 -0
- package/golang/strconv/ParseInt.js +27 -0
- package/golang/strconv/index.js +6 -0
- package/golang/strings/Compare.js +19 -0
- package/golang/strings/Contains.js +7 -9
- package/golang/strings/ContainsAny.js +18 -0
- package/golang/strings/Count.js +20 -22
- package/golang/strings/EqualFold.js +13 -0
- package/golang/strings/Fields.js +12 -0
- package/golang/strings/HasPrefix.js +15 -0
- package/golang/strings/HasSuffix.js +20 -0
- package/golang/strings/Index.js +11 -0
- package/golang/strings/Index2.js +9 -11
- package/golang/strings/IndexAny.js +18 -0
- package/golang/strings/Join.js +16 -0
- package/golang/strings/LastIndex.js +10 -12
- package/golang/strings/LastIndexAny.js +18 -0
- package/golang/strings/Repeat.js +19 -0
- package/golang/strings/Replace.js +44 -0
- package/golang/strings/Split.js +24 -0
- package/golang/strings/ToLower.js +9 -0
- package/golang/strings/ToUpper.js +9 -0
- package/golang/strings/Trim.js +19 -0
- package/golang/strings/TrimLeft.js +15 -0
- package/golang/strings/TrimPrefix.js +14 -0
- package/golang/strings/TrimRight.js +15 -0
- package/golang/strings/TrimSpace.js +10 -0
- package/golang/strings/TrimSuffix.js +14 -0
- package/golang/strings/index.js +25 -7
- package/index.js +5 -8
- package/julia/Base/abs.js +13 -0
- package/julia/Base/ceil.js +16 -0
- package/julia/Base/floor.js +14 -0
- package/julia/Base/index.js +3 -0
- package/lua/math/abs.js +13 -0
- package/lua/math/ceil.js +16 -0
- package/lua/math/floor.js +14 -0
- package/lua/math/index.js +3 -0
- package/package.json +37 -51
- package/perl/POSIX/ceil.js +16 -0
- package/perl/POSIX/floor.js +14 -0
- package/perl/POSIX/index.js +2 -0
- package/perl/core/index.js +1 -0
- package/perl/core/length.js +16 -0
- package/php/_helpers/_bc.js +524 -515
- package/php/_helpers/_phpCastString.js +20 -25
- package/php/_helpers/_php_cast_float.js +5 -10
- package/php/_helpers/_php_cast_int.js +6 -11
- package/php/_helpers/index.js +4 -7
- package/php/array/array_change_key_case.js +11 -16
- package/php/array/array_chunk.js +20 -23
- package/php/array/array_column.js +22 -72
- package/php/array/array_combine.js +13 -18
- package/php/array/array_count_values.js +35 -39
- package/php/array/array_diff.js +11 -14
- package/php/array/array_diff_assoc.js +11 -14
- package/php/array/array_diff_key.js +11 -14
- package/php/array/array_diff_uassoc.js +15 -19
- package/php/array/array_diff_ukey.js +14 -17
- package/php/array/array_fill.js +11 -13
- package/php/array/array_fill_keys.js +5 -8
- package/php/array/array_filter.js +12 -13
- package/php/array/array_flip.js +13 -15
- package/php/array/array_intersect.js +13 -16
- package/php/array/array_intersect_assoc.js +13 -16
- package/php/array/array_intersect_key.js +15 -18
- package/php/array/array_intersect_uassoc.js +17 -20
- package/php/array/array_intersect_ukey.js +17 -20
- package/php/array/array_key_exists.js +4 -7
- package/php/array/array_keys.js +22 -24
- package/php/array/array_map.js +24 -29
- package/php/array/array_merge.js +22 -25
- package/php/array/array_merge_recursive.js +51 -27
- package/php/array/array_multisort.js +138 -130
- package/php/array/array_pad.js +24 -26
- package/php/array/array_pop.js +10 -13
- package/php/array/array_product.js +15 -17
- package/php/array/array_push.js +16 -19
- package/php/array/array_rand.js +11 -14
- package/php/array/array_reduce.js +11 -14
- package/php/array/array_replace.js +9 -12
- package/php/array/array_replace_recursive.js +20 -24
- package/php/array/array_reverse.js +12 -15
- package/php/array/array_search.js +27 -29
- package/php/array/array_shift.js +3 -6
- package/php/array/array_slice.js +37 -39
- package/php/array/array_splice.js +64 -69
- package/php/array/array_sum.js +7 -12
- package/php/array/array_udiff.js +14 -17
- package/php/array/array_udiff_assoc.js +14 -17
- package/php/array/array_udiff_uassoc.js +17 -20
- package/php/array/array_uintersect.js +16 -19
- package/php/array/array_uintersect_uassoc.js +18 -21
- package/php/array/array_unique.js +12 -15
- package/php/array/array_unshift.js +4 -7
- package/php/array/array_values.js +11 -13
- package/php/array/array_walk.js +10 -15
- package/php/array/array_walk_recursive.js +15 -20
- package/php/array/arsort.js +50 -52
- package/php/array/asort.js +50 -51
- package/php/array/count.js +15 -14
- package/php/array/current.js +30 -32
- package/php/array/each.js +32 -35
- package/php/array/end.js +27 -30
- package/php/array/in_array.js +7 -10
- package/php/array/index.js +73 -76
- package/php/array/key.js +32 -34
- package/php/array/krsort.js +50 -51
- package/php/array/ksort.js +50 -51
- package/php/array/natcasesort.js +37 -38
- package/php/array/natsort.js +35 -36
- package/php/array/next.js +34 -36
- package/php/array/pos.js +10 -12
- package/php/array/prev.js +32 -34
- package/php/array/range.js +30 -33
- package/php/array/reset.js +24 -27
- package/php/array/rsort.js +47 -49
- package/php/array/shuffle.js +16 -18
- package/php/array/sizeof.js +3 -6
- package/php/array/sort.js +43 -45
- package/php/array/uasort.js +19 -21
- package/php/array/uksort.js +22 -24
- package/php/array/usort.js +20 -22
- package/php/bc/bcadd.js +16 -19
- package/php/bc/bccomp.js +12 -15
- package/php/bc/bcdiv.js +17 -20
- package/php/bc/bcmul.js +16 -19
- package/php/bc/bcround.js +21 -24
- package/php/bc/bcscale.js +8 -11
- package/php/bc/bcsub.js +16 -19
- package/php/bc/index.js +7 -10
- package/php/ctype/ctype_alnum.js +14 -16
- package/php/ctype/ctype_alpha.js +14 -16
- package/php/ctype/ctype_cntrl.js +9 -12
- package/php/ctype/ctype_digit.js +14 -16
- package/php/ctype/ctype_graph.js +14 -16
- package/php/ctype/ctype_lower.js +14 -16
- package/php/ctype/ctype_print.js +14 -16
- package/php/ctype/ctype_punct.js +14 -16
- package/php/ctype/ctype_space.js +9 -12
- package/php/ctype/ctype_upper.js +14 -16
- package/php/ctype/ctype_xdigit.js +14 -16
- package/php/ctype/index.js +11 -14
- package/php/datetime/checkdate.js +15 -17
- package/php/datetime/date.js +142 -123
- package/php/datetime/date_parse.js +18 -21
- package/php/datetime/getdate.js +38 -24
- package/php/datetime/gettimeofday.js +7 -10
- package/php/datetime/gmdate.js +17 -16
- package/php/datetime/gmmktime.js +23 -25
- package/php/datetime/gmstrftime.js +17 -14
- package/php/datetime/idate.js +44 -38
- package/php/datetime/index.js +15 -18
- package/php/datetime/microtime.js +11 -14
- package/php/datetime/mktime.js +14 -17
- package/php/datetime/strftime.js +122 -113
- package/php/datetime/strptime.js +210 -191
- package/php/datetime/strtotime.js +615 -496
- package/php/datetime/time.js +11 -13
- package/php/exec/escapeshellarg.js +16 -18
- package/php/exec/index.js +1 -4
- package/php/filesystem/basename.js +22 -24
- package/php/filesystem/dirname.js +12 -14
- package/php/filesystem/file_exists.js +12 -0
- package/php/filesystem/file_get_contents.js +3 -6
- package/php/filesystem/index.js +6 -8
- package/php/filesystem/pathinfo.js +47 -46
- package/php/filesystem/realpath.js +16 -19
- package/php/funchand/call_user_func.js +4 -7
- package/php/funchand/call_user_func_array.js +19 -22
- package/php/funchand/create_function.js +4 -7
- package/php/funchand/function_exists.js +4 -8
- package/php/funchand/get_defined_functions.js +25 -32
- package/php/funchand/index.js +5 -8
- package/php/i18n/i18n_loc_get_default.js +7 -10
- package/php/i18n/i18n_loc_set_default.js +12 -15
- package/php/i18n/index.js +2 -5
- package/php/index.js +20 -23
- package/php/info/assert_options.js +25 -27
- package/php/info/getenv.js +8 -10
- package/php/info/index.js +6 -9
- package/php/info/ini_get.js +9 -12
- package/php/info/ini_set.js +32 -34
- package/php/info/set_time_limit.js +8 -11
- package/php/info/version_compare.js +43 -44
- package/php/json/index.js +3 -6
- package/php/json/json_decode.js +42 -28
- package/php/json/json_encode.js +89 -66
- package/php/json/json_last_error.js +11 -13
- package/php/math/abs.js +2 -5
- package/php/math/acos.js +2 -5
- package/php/math/acosh.js +7 -9
- package/php/math/asin.js +2 -5
- package/php/math/asinh.js +7 -9
- package/php/math/atan.js +7 -9
- package/php/math/atan2.js +7 -9
- package/php/math/atanh.js +2 -5
- package/php/math/base_convert.js +8 -10
- package/php/math/bindec.js +12 -14
- package/php/math/ceil.js +7 -9
- package/php/math/cos.js +7 -9
- package/php/math/cosh.js +7 -9
- package/php/math/decbin.js +16 -18
- package/php/math/dechex.js +3 -6
- package/php/math/decoct.js +13 -15
- package/php/math/deg2rad.js +8 -10
- package/php/math/exp.js +7 -9
- package/php/math/expm1.js +9 -11
- package/php/math/floor.js +7 -9
- package/php/math/fmod.js +27 -29
- package/php/math/getrandmax.js +7 -9
- package/php/math/hexdec.js +10 -12
- package/php/math/hypot.js +8 -11
- package/php/math/index.js +46 -49
- package/php/math/is_finite.js +9 -14
- package/php/math/is_infinite.js +9 -14
- package/php/math/is_nan.js +8 -13
- package/php/math/lcg_value.js +8 -10
- package/php/math/log.js +8 -10
- package/php/math/log10.js +12 -14
- package/php/math/log1p.js +15 -17
- package/php/math/max.js +54 -59
- package/php/math/min.js +54 -59
- package/php/math/mt_getrandmax.js +7 -9
- package/php/math/mt_rand.js +15 -17
- package/php/math/octdec.js +8 -10
- package/php/math/pi.js +2 -5
- package/php/math/pow.js +2 -5
- package/php/math/rad2deg.js +8 -10
- package/php/math/rand.js +15 -17
- package/php/math/round.js +48 -49
- package/php/math/sin.js +7 -9
- package/php/math/sinh.js +7 -9
- package/php/math/sqrt.js +7 -9
- package/php/math/tan.js +7 -9
- package/php/math/tanh.js +8 -10
- package/php/misc/index.js +2 -5
- package/php/misc/pack.js +173 -165
- package/php/misc/uniqid.js +20 -23
- package/php/net-gopher/gopher_parsedir.js +27 -29
- package/php/net-gopher/index.js +1 -4
- package/php/network/index.js +6 -9
- package/php/network/inet_ntop.js +15 -15
- package/php/network/inet_pton.js +30 -34
- package/php/network/ip2long.js +25 -15
- package/php/network/long2ip.js +8 -10
- package/php/network/setcookie.js +11 -13
- package/php/network/setrawcookie.js +16 -19
- package/php/pcre/index.js +4 -7
- package/php/pcre/preg_match.js +3 -6
- package/php/pcre/preg_quote.js +2 -5
- package/php/pcre/preg_replace.js +8 -11
- package/php/pcre/sql_regcase.js +17 -20
- package/php/strings/addcslashes.js +86 -88
- package/php/strings/addslashes.js +15 -16
- package/php/strings/bin2hex.js +19 -43
- package/php/strings/chop.js +8 -10
- package/php/strings/chr.js +12 -14
- package/php/strings/chunk_split.js +15 -17
- package/php/strings/convert_cyr_string.js +137 -50
- package/php/strings/convert_uuencode.js +35 -38
- package/php/strings/count_chars.js +29 -27
- package/php/strings/crc32.js +276 -21
- package/php/strings/echo.js +28 -30
- package/php/strings/explode.js +31 -26
- package/php/strings/get_html_translation_table.js +123 -122
- package/php/strings/hex2bin.js +21 -21
- package/php/strings/html_entity_decode.js +31 -33
- package/php/strings/htmlentities.js +38 -34
- package/php/strings/htmlspecialchars.js +20 -23
- package/php/strings/htmlspecialchars_decode.js +19 -21
- package/php/strings/implode.js +23 -27
- package/php/strings/index.js +91 -94
- package/php/strings/join.js +8 -10
- package/php/strings/lcfirst.js +9 -11
- package/php/strings/levenshtein.js +37 -39
- package/php/strings/localeconv.js +12 -15
- package/php/strings/ltrim.js +12 -14
- package/php/strings/md5.js +216 -223
- package/php/strings/md5_file.js +17 -19
- package/php/strings/metaphone.js +112 -117
- package/php/strings/money_format.js +139 -126
- package/php/strings/nl2br.js +24 -26
- package/php/strings/nl_langinfo.js +32 -35
- package/php/strings/number_format.js +19 -22
- package/php/strings/ord.js +19 -21
- package/php/strings/parse_str.js +53 -56
- package/php/strings/printf.js +6 -9
- package/php/strings/quoted_printable_decode.js +7 -10
- package/php/strings/quoted_printable_encode.js +19 -20
- package/php/strings/quotemeta.js +7 -9
- package/php/strings/rtrim.js +14 -16
- package/php/strings/setlocale.js +148 -104
- package/php/strings/sha1.js +108 -106
- package/php/strings/sha1_file.js +15 -17
- package/php/strings/similar_text.js +34 -33
- package/php/strings/soundex.js +34 -36
- package/php/strings/split.js +8 -10
- package/php/strings/sprintf.js +112 -114
- package/php/strings/sscanf.js +99 -96
- package/php/strings/str_getcsv.js +37 -32
- package/php/strings/str_ireplace.js +50 -55
- package/php/strings/str_pad.js +18 -21
- package/php/strings/str_repeat.js +14 -16
- package/php/strings/str_replace.js +32 -37
- package/php/strings/str_rot13.js +15 -17
- package/php/strings/str_shuffle.js +12 -15
- package/php/strings/str_split.js +19 -21
- package/php/strings/str_word_count.js +51 -50
- package/php/strings/strcasecmp.js +12 -14
- package/php/strings/strchr.js +10 -12
- package/php/strings/strcmp.js +12 -14
- package/php/strings/strcoll.js +9 -12
- package/php/strings/strcspn.js +30 -25
- package/php/strings/strip_tags.js +50 -52
- package/php/strings/stripos.js +12 -14
- package/php/strings/stripslashes.js +8 -10
- package/php/strings/stristr.js +15 -17
- package/php/strings/strlen.js +23 -26
- package/php/strings/strnatcasecmp.js +6 -8
- package/php/strings/strnatcmp.js +47 -46
- package/php/strings/strncasecmp.js +30 -32
- package/php/strings/strncmp.js +5 -7
- package/php/strings/strpbrk.js +12 -14
- package/php/strings/strpos.js +11 -13
- package/php/strings/strrchr.js +7 -10
- package/php/strings/strrev.js +188 -10
- package/php/strings/strripos.js +16 -18
- package/php/strings/strrpos.js +20 -22
- package/php/strings/strspn.js +24 -26
- package/php/strings/strstr.js +20 -22
- package/php/strings/strtok.js +14 -16
- package/php/strings/strtolower.js +8 -10
- package/php/strings/strtoupper.js +8 -10
- package/php/strings/strtr.js +38 -43
- package/php/strings/substr.js +14 -18
- package/php/strings/substr_compare.js +18 -20
- package/php/strings/substr_count.js +11 -14
- package/php/strings/substr_replace.js +5 -8
- package/php/strings/trim.js +53 -32
- package/php/strings/ucfirst.js +11 -13
- package/php/strings/ucwords.js +3 -6
- package/php/strings/vprintf.js +6 -9
- package/php/strings/vsprintf.js +8 -10
- package/php/strings/wordwrap.js +32 -35
- package/php/url/base64_decode.js +42 -40
- package/php/url/base64_encode.js +51 -53
- package/php/url/http_build_query.js +27 -32
- package/php/url/index.js +8 -11
- package/php/url/parse_url.js +61 -25
- package/php/url/rawurldecode.js +8 -8
- package/php/url/rawurlencode.js +9 -6
- package/php/url/urldecode.js +9 -8
- package/php/url/urlencode.js +11 -6
- package/php/var/boolval.js +31 -33
- package/php/var/doubleval.js +10 -12
- package/php/var/empty.js +11 -16
- package/php/var/floatval.js +13 -15
- package/php/var/gettype.js +22 -23
- package/php/var/index.js +30 -33
- package/php/var/intval.js +35 -39
- package/php/var/is_array.js +27 -31
- package/php/var/is_binary.js +2 -5
- package/php/var/is_bool.js +10 -12
- package/php/var/is_buffer.js +2 -5
- package/php/var/is_callable.js +34 -35
- package/php/var/is_double.js +10 -12
- package/php/var/is_float.js +12 -14
- package/php/var/is_int.js +20 -22
- package/php/var/is_integer.js +12 -14
- package/php/var/is_long.js +3 -6
- package/php/var/is_null.js +9 -11
- package/php/var/is_numeric.js +30 -6
- package/php/var/is_object.js +4 -9
- package/php/var/is_real.js +3 -6
- package/php/var/is_scalar.js +2 -8
- package/php/var/is_string.js +9 -11
- package/php/var/is_unicode.js +12 -15
- package/php/var/isset.js +9 -12
- package/php/var/print_r.js +49 -53
- package/php/var/serialize.js +47 -52
- package/php/var/serialize.vitest.ts +10 -0
- package/php/var/strval.js +10 -13
- package/php/var/unserialize.js +168 -202
- package/php/var/var_dump.js +105 -104
- package/php/var/var_export.js +64 -66
- package/php/xdiff/index.js +2 -5
- package/php/xdiff/xdiff_string_diff.js +240 -226
- package/php/xdiff/xdiff_string_patch.js +98 -93
- package/php/xml/index.js +2 -5
- package/php/xml/utf8_decode.js +40 -42
- package/php/xml/utf8_encode.js +40 -42
- package/python/index.js +1 -4
- package/python/math/ceil.js +17 -0
- package/python/math/exp.js +12 -0
- package/python/math/fabs.js +14 -0
- package/python/math/factorial.js +29 -0
- package/python/math/floor.js +14 -0
- package/python/math/gcd.js +23 -0
- package/python/math/index.js +15 -0
- package/python/math/isfinite.js +14 -0
- package/python/math/isinf.js +14 -0
- package/python/math/isnan.js +14 -0
- package/python/math/log.js +16 -0
- package/python/math/log10.js +14 -0
- package/python/math/log2.js +14 -0
- package/python/math/pow.js +14 -0
- package/python/math/sqrt.js +14 -0
- package/python/math/trunc.js +14 -0
- package/python/string/ascii_letters.js +14 -14
- package/python/string/ascii_lowercase.js +12 -16
- package/python/string/ascii_uppercase.js +12 -16
- package/python/string/capwords.js +4 -7
- package/python/string/digits.js +10 -0
- package/python/string/hexdigits.js +10 -0
- package/python/string/index.js +10 -8
- package/python/string/octdigits.js +10 -0
- package/python/string/printable.js +15 -0
- package/python/string/punctuation.js +5 -7
- package/python/string/whitespace.js +10 -0
- package/r/base/abs.js +13 -0
- package/r/base/ceiling.js +16 -0
- package/r/base/floor.js +14 -0
- package/r/base/index.js +3 -0
- package/ruby/Array/compact.js +18 -0
- package/ruby/Array/first.js +22 -0
- package/ruby/Array/flatten.js +22 -0
- package/ruby/Array/index.js +6 -0
- package/ruby/Array/last.js +22 -0
- package/ruby/Array/sample.js +31 -0
- package/ruby/Array/uniq.js +16 -0
- package/ruby/Math/acos.js +2 -5
- package/ruby/Math/asin.js +11 -0
- package/ruby/Math/atan.js +11 -0
- package/ruby/Math/cbrt.js +13 -0
- package/ruby/Math/cos.js +12 -0
- package/ruby/Math/cosh.js +11 -0
- package/ruby/Math/exp.js +11 -0
- package/ruby/Math/index.js +15 -4
- package/ruby/Math/log.js +11 -0
- package/ruby/Math/log10.js +13 -0
- package/ruby/Math/log2.js +13 -0
- package/ruby/Math/sin.js +12 -0
- package/ruby/Math/sinh.js +11 -0
- package/ruby/Math/sqrt.js +13 -0
- package/ruby/Math/tan.js +11 -0
- package/ruby/Math/tanh.js +11 -0
- package/ruby/String/capitalize.js +19 -0
- package/ruby/String/chomp.js +27 -0
- package/ruby/String/chop.js +25 -0
- package/ruby/String/downcase.js +10 -0
- package/ruby/String/end_with.js +17 -0
- package/ruby/String/include.js +12 -0
- package/ruby/String/index.js +11 -0
- package/ruby/String/length.js +12 -0
- package/ruby/String/reverse.js +12 -0
- package/ruby/String/start_with.js +14 -0
- package/ruby/String/strip.js +12 -0
- package/ruby/String/upcase.js +10 -0
- package/ruby/index.js +1 -4
- package/_util/cli.js +0 -14
- package/_util/cli.js.map +0 -1
- package/_util/util.js +0 -620
- package/_util/util.js.map +0 -1
- package/c/index.js.map +0 -1
- package/c/math/abs.js.map +0 -1
- package/c/math/frexp.js.map +0 -1
- package/c/math/index.js.map +0 -1
- package/c/stdio/index.js.map +0 -1
- package/c/stdio/sprintf.js.map +0 -1
- package/golang/index.js.map +0 -1
- package/golang/strings/Contains.js.map +0 -1
- package/golang/strings/Count.js.map +0 -1
- package/golang/strings/Index2.js.map +0 -1
- package/golang/strings/LastIndex.js.map +0 -1
- package/golang/strings/index.js.map +0 -1
- package/index.js.map +0 -1
- package/php/_helpers/_bc.js.map +0 -1
- package/php/_helpers/_phpCastString.js.map +0 -1
- package/php/_helpers/_php_cast_float.js.map +0 -1
- package/php/_helpers/_php_cast_int.js.map +0 -1
- package/php/_helpers/index.js.map +0 -1
- package/php/array/array_change_key_case.js.map +0 -1
- package/php/array/array_chunk.js.map +0 -1
- package/php/array/array_column.js.map +0 -1
- package/php/array/array_combine.js.map +0 -1
- package/php/array/array_count_values.js.map +0 -1
- package/php/array/array_diff.js.map +0 -1
- package/php/array/array_diff_assoc.js.map +0 -1
- package/php/array/array_diff_key.js.map +0 -1
- package/php/array/array_diff_uassoc.js.map +0 -1
- package/php/array/array_diff_ukey.js.map +0 -1
- package/php/array/array_fill.js.map +0 -1
- package/php/array/array_fill_keys.js.map +0 -1
- package/php/array/array_filter.js.map +0 -1
- package/php/array/array_flip.js.map +0 -1
- package/php/array/array_intersect.js.map +0 -1
- package/php/array/array_intersect_assoc.js.map +0 -1
- package/php/array/array_intersect_key.js.map +0 -1
- package/php/array/array_intersect_uassoc.js.map +0 -1
- package/php/array/array_intersect_ukey.js.map +0 -1
- package/php/array/array_key_exists.js.map +0 -1
- package/php/array/array_keys.js.map +0 -1
- package/php/array/array_map.js.map +0 -1
- package/php/array/array_merge.js.map +0 -1
- package/php/array/array_merge_recursive.js.map +0 -1
- package/php/array/array_multisort.js.map +0 -1
- package/php/array/array_pad.js.map +0 -1
- package/php/array/array_pop.js.map +0 -1
- package/php/array/array_product.js.map +0 -1
- package/php/array/array_push.js.map +0 -1
- package/php/array/array_rand.js.map +0 -1
- package/php/array/array_reduce.js.map +0 -1
- package/php/array/array_replace.js.map +0 -1
- package/php/array/array_replace_recursive.js.map +0 -1
- package/php/array/array_reverse.js.map +0 -1
- package/php/array/array_search.js.map +0 -1
- package/php/array/array_shift.js.map +0 -1
- package/php/array/array_slice.js.map +0 -1
- package/php/array/array_splice.js.map +0 -1
- package/php/array/array_sum.js.map +0 -1
- package/php/array/array_udiff.js.map +0 -1
- package/php/array/array_udiff_assoc.js.map +0 -1
- package/php/array/array_udiff_uassoc.js.map +0 -1
- package/php/array/array_uintersect.js.map +0 -1
- package/php/array/array_uintersect_uassoc.js.map +0 -1
- package/php/array/array_unique.js.map +0 -1
- package/php/array/array_unshift.js.map +0 -1
- package/php/array/array_values.js.map +0 -1
- package/php/array/array_walk.js.map +0 -1
- package/php/array/array_walk_recursive.js.map +0 -1
- package/php/array/arsort.js.map +0 -1
- package/php/array/asort.js.map +0 -1
- package/php/array/count.js.map +0 -1
- package/php/array/current.js.map +0 -1
- package/php/array/each.js.map +0 -1
- package/php/array/end.js.map +0 -1
- package/php/array/in_array.js.map +0 -1
- package/php/array/index.js.map +0 -1
- package/php/array/key.js.map +0 -1
- package/php/array/krsort.js.map +0 -1
- package/php/array/ksort.js.map +0 -1
- package/php/array/natcasesort.js.map +0 -1
- package/php/array/natsort.js.map +0 -1
- package/php/array/next.js.map +0 -1
- package/php/array/pos.js.map +0 -1
- package/php/array/prev.js.map +0 -1
- package/php/array/range.js.map +0 -1
- package/php/array/reset.js.map +0 -1
- package/php/array/rsort.js.map +0 -1
- package/php/array/shuffle.js.map +0 -1
- package/php/array/sizeof.js.map +0 -1
- package/php/array/sort.js.map +0 -1
- package/php/array/uasort.js.map +0 -1
- package/php/array/uksort.js.map +0 -1
- package/php/array/usort.js.map +0 -1
- package/php/bc/bcadd.js.map +0 -1
- package/php/bc/bccomp.js.map +0 -1
- package/php/bc/bcdiv.js.map +0 -1
- package/php/bc/bcmul.js.map +0 -1
- package/php/bc/bcround.js.map +0 -1
- package/php/bc/bcscale.js.map +0 -1
- package/php/bc/bcsub.js.map +0 -1
- package/php/bc/index.js.map +0 -1
- package/php/ctype/ctype_alnum.js.map +0 -1
- package/php/ctype/ctype_alpha.js.map +0 -1
- package/php/ctype/ctype_cntrl.js.map +0 -1
- package/php/ctype/ctype_digit.js.map +0 -1
- package/php/ctype/ctype_graph.js.map +0 -1
- package/php/ctype/ctype_lower.js.map +0 -1
- package/php/ctype/ctype_print.js.map +0 -1
- package/php/ctype/ctype_punct.js.map +0 -1
- package/php/ctype/ctype_space.js.map +0 -1
- package/php/ctype/ctype_upper.js.map +0 -1
- package/php/ctype/ctype_xdigit.js.map +0 -1
- package/php/ctype/index.js.map +0 -1
- package/php/datetime/checkdate.js.map +0 -1
- package/php/datetime/date.js.map +0 -1
- package/php/datetime/date_parse.js.map +0 -1
- package/php/datetime/getdate.js.map +0 -1
- package/php/datetime/gettimeofday.js.map +0 -1
- package/php/datetime/gmdate.js.map +0 -1
- package/php/datetime/gmmktime.js.map +0 -1
- package/php/datetime/gmstrftime.js.map +0 -1
- package/php/datetime/idate.js.map +0 -1
- package/php/datetime/index.js.map +0 -1
- package/php/datetime/microtime.js.map +0 -1
- package/php/datetime/mktime.js.map +0 -1
- package/php/datetime/strftime.js.map +0 -1
- package/php/datetime/strptime.js.map +0 -1
- package/php/datetime/strtotime.js.map +0 -1
- package/php/datetime/time.js.map +0 -1
- package/php/exec/escapeshellarg.js.map +0 -1
- package/php/exec/index.js.map +0 -1
- package/php/filesystem/basename.js.map +0 -1
- package/php/filesystem/dirname.js.map +0 -1
- package/php/filesystem/file_get_contents.js.map +0 -1
- package/php/filesystem/index.js.map +0 -1
- package/php/filesystem/pathinfo.js.map +0 -1
- package/php/filesystem/realpath.js.map +0 -1
- package/php/funchand/call_user_func.js.map +0 -1
- package/php/funchand/call_user_func_array.js.map +0 -1
- package/php/funchand/create_function.js.map +0 -1
- package/php/funchand/function_exists.js.map +0 -1
- package/php/funchand/get_defined_functions.js.map +0 -1
- package/php/funchand/index.js.map +0 -1
- package/php/i18n/i18n_loc_get_default.js.map +0 -1
- package/php/i18n/i18n_loc_set_default.js.map +0 -1
- package/php/i18n/index.js.map +0 -1
- package/php/index.js.map +0 -1
- package/php/info/assert_options.js.map +0 -1
- package/php/info/getenv.js.map +0 -1
- package/php/info/index.js.map +0 -1
- package/php/info/ini_get.js.map +0 -1
- package/php/info/ini_set.js.map +0 -1
- package/php/info/set_time_limit.js.map +0 -1
- package/php/info/version_compare.js.map +0 -1
- package/php/json/index.js.map +0 -1
- package/php/json/json_decode.js.map +0 -1
- package/php/json/json_encode.js.map +0 -1
- package/php/json/json_last_error.js.map +0 -1
- package/php/math/abs.js.map +0 -1
- package/php/math/acos.js.map +0 -1
- package/php/math/acosh.js.map +0 -1
- package/php/math/asin.js.map +0 -1
- package/php/math/asinh.js.map +0 -1
- package/php/math/atan.js.map +0 -1
- package/php/math/atan2.js.map +0 -1
- package/php/math/atanh.js.map +0 -1
- package/php/math/base_convert.js.map +0 -1
- package/php/math/bindec.js.map +0 -1
- package/php/math/ceil.js.map +0 -1
- package/php/math/cos.js.map +0 -1
- package/php/math/cosh.js.map +0 -1
- package/php/math/decbin.js.map +0 -1
- package/php/math/dechex.js.map +0 -1
- package/php/math/decoct.js.map +0 -1
- package/php/math/deg2rad.js.map +0 -1
- package/php/math/exp.js.map +0 -1
- package/php/math/expm1.js.map +0 -1
- package/php/math/floor.js.map +0 -1
- package/php/math/fmod.js.map +0 -1
- package/php/math/getrandmax.js.map +0 -1
- package/php/math/hexdec.js.map +0 -1
- package/php/math/hypot.js.map +0 -1
- package/php/math/index.js.map +0 -1
- package/php/math/is_finite.js.map +0 -1
- package/php/math/is_infinite.js.map +0 -1
- package/php/math/is_nan.js.map +0 -1
- package/php/math/lcg_value.js.map +0 -1
- package/php/math/log.js.map +0 -1
- package/php/math/log10.js.map +0 -1
- package/php/math/log1p.js.map +0 -1
- package/php/math/max.js.map +0 -1
- package/php/math/min.js.map +0 -1
- package/php/math/mt_getrandmax.js.map +0 -1
- package/php/math/mt_rand.js.map +0 -1
- package/php/math/octdec.js.map +0 -1
- package/php/math/pi.js.map +0 -1
- package/php/math/pow.js.map +0 -1
- package/php/math/rad2deg.js.map +0 -1
- package/php/math/rand.js.map +0 -1
- package/php/math/round.js.map +0 -1
- package/php/math/sin.js.map +0 -1
- package/php/math/sinh.js.map +0 -1
- package/php/math/sqrt.js.map +0 -1
- package/php/math/tan.js.map +0 -1
- package/php/math/tanh.js.map +0 -1
- package/php/misc/index.js.map +0 -1
- package/php/misc/pack.js.map +0 -1
- package/php/misc/uniqid.js.map +0 -1
- package/php/net-gopher/gopher_parsedir.js.map +0 -1
- package/php/net-gopher/index.js.map +0 -1
- package/php/network/index.js.map +0 -1
- package/php/network/inet_ntop.js.map +0 -1
- package/php/network/inet_pton.js.map +0 -1
- package/php/network/ip2long.js.map +0 -1
- package/php/network/long2ip.js.map +0 -1
- package/php/network/setcookie.js.map +0 -1
- package/php/network/setrawcookie.js.map +0 -1
- package/php/pcre/index.js.map +0 -1
- package/php/pcre/preg_match.js.map +0 -1
- package/php/pcre/preg_quote.js.map +0 -1
- package/php/pcre/preg_replace.js.map +0 -1
- package/php/pcre/sql_regcase.js.map +0 -1
- package/php/strings/addcslashes.js.map +0 -1
- package/php/strings/addslashes.js.map +0 -1
- package/php/strings/bin2hex.js.map +0 -1
- package/php/strings/chop.js.map +0 -1
- package/php/strings/chr.js.map +0 -1
- package/php/strings/chunk_split.js.map +0 -1
- package/php/strings/convert_cyr_string.js.map +0 -1
- package/php/strings/convert_uuencode.js.map +0 -1
- package/php/strings/count_chars.js.map +0 -1
- package/php/strings/crc32.js.map +0 -1
- package/php/strings/echo.js.map +0 -1
- package/php/strings/explode.js.map +0 -1
- package/php/strings/get_html_translation_table.js.map +0 -1
- package/php/strings/hex2bin.js.map +0 -1
- package/php/strings/html_entity_decode.js.map +0 -1
- package/php/strings/htmlentities.js.map +0 -1
- package/php/strings/htmlspecialchars.js.map +0 -1
- package/php/strings/htmlspecialchars_decode.js.map +0 -1
- package/php/strings/implode.js.map +0 -1
- package/php/strings/index.js.map +0 -1
- package/php/strings/join.js.map +0 -1
- package/php/strings/lcfirst.js.map +0 -1
- package/php/strings/levenshtein.js.map +0 -1
- package/php/strings/localeconv.js.map +0 -1
- package/php/strings/ltrim.js.map +0 -1
- package/php/strings/md5.js.map +0 -1
- package/php/strings/md5_file.js.map +0 -1
- package/php/strings/metaphone.js.map +0 -1
- package/php/strings/money_format.js.map +0 -1
- package/php/strings/nl2br.js.map +0 -1
- package/php/strings/nl_langinfo.js.map +0 -1
- package/php/strings/number_format.js.map +0 -1
- package/php/strings/ord.js.map +0 -1
- package/php/strings/parse_str.js.map +0 -1
- package/php/strings/printf.js.map +0 -1
- package/php/strings/quoted_printable_decode.js.map +0 -1
- package/php/strings/quoted_printable_encode.js.map +0 -1
- package/php/strings/quotemeta.js.map +0 -1
- package/php/strings/rtrim.js.map +0 -1
- package/php/strings/setlocale.js.map +0 -1
- package/php/strings/sha1.js.map +0 -1
- package/php/strings/sha1_file.js.map +0 -1
- package/php/strings/similar_text.js.map +0 -1
- package/php/strings/soundex.js.map +0 -1
- package/php/strings/split.js.map +0 -1
- package/php/strings/sprintf.js.map +0 -1
- package/php/strings/sscanf.js.map +0 -1
- package/php/strings/str_getcsv.js.map +0 -1
- package/php/strings/str_ireplace.js.map +0 -1
- package/php/strings/str_pad.js.map +0 -1
- package/php/strings/str_repeat.js.map +0 -1
- package/php/strings/str_replace.js.map +0 -1
- package/php/strings/str_rot13.js.map +0 -1
- package/php/strings/str_shuffle.js.map +0 -1
- package/php/strings/str_split.js.map +0 -1
- package/php/strings/str_word_count.js.map +0 -1
- package/php/strings/strcasecmp.js.map +0 -1
- package/php/strings/strchr.js.map +0 -1
- package/php/strings/strcmp.js.map +0 -1
- package/php/strings/strcoll.js.map +0 -1
- package/php/strings/strcspn.js.map +0 -1
- package/php/strings/strip_tags.js.map +0 -1
- package/php/strings/stripos.js.map +0 -1
- package/php/strings/stripslashes.js.map +0 -1
- package/php/strings/stristr.js.map +0 -1
- package/php/strings/strlen.js.map +0 -1
- package/php/strings/strnatcasecmp.js.map +0 -1
- package/php/strings/strnatcmp.js.map +0 -1
- package/php/strings/strncasecmp.js.map +0 -1
- package/php/strings/strncmp.js.map +0 -1
- package/php/strings/strpbrk.js.map +0 -1
- package/php/strings/strpos.js.map +0 -1
- package/php/strings/strrchr.js.map +0 -1
- package/php/strings/strrev.js.map +0 -1
- package/php/strings/strripos.js.map +0 -1
- package/php/strings/strrpos.js.map +0 -1
- package/php/strings/strspn.js.map +0 -1
- package/php/strings/strstr.js.map +0 -1
- package/php/strings/strtok.js.map +0 -1
- package/php/strings/strtolower.js.map +0 -1
- package/php/strings/strtoupper.js.map +0 -1
- package/php/strings/strtr.js.map +0 -1
- package/php/strings/substr.js.map +0 -1
- package/php/strings/substr_compare.js.map +0 -1
- package/php/strings/substr_count.js.map +0 -1
- package/php/strings/substr_replace.js.map +0 -1
- package/php/strings/trim.js.map +0 -1
- package/php/strings/ucfirst.js.map +0 -1
- package/php/strings/ucwords.js.map +0 -1
- package/php/strings/vprintf.js.map +0 -1
- package/php/strings/vsprintf.js.map +0 -1
- package/php/strings/wordwrap.js.map +0 -1
- package/php/url/base64_decode.js.map +0 -1
- package/php/url/base64_encode.js.map +0 -1
- package/php/url/http_build_query.js.map +0 -1
- package/php/url/index.js.map +0 -1
- package/php/url/parse_url.js.map +0 -1
- package/php/url/rawurldecode.js.map +0 -1
- package/php/url/rawurlencode.js.map +0 -1
- package/php/url/urldecode.js.map +0 -1
- package/php/url/urlencode.js.map +0 -1
- package/php/var/boolval.js.map +0 -1
- package/php/var/doubleval.js.map +0 -1
- package/php/var/empty.js.map +0 -1
- package/php/var/floatval.js.map +0 -1
- package/php/var/gettype.js.map +0 -1
- package/php/var/index.js.map +0 -1
- package/php/var/intval.js.map +0 -1
- package/php/var/is_array.js.map +0 -1
- package/php/var/is_binary.js.map +0 -1
- package/php/var/is_bool.js.map +0 -1
- package/php/var/is_buffer.js.map +0 -1
- package/php/var/is_callable.js.map +0 -1
- package/php/var/is_double.js.map +0 -1
- package/php/var/is_float.js.map +0 -1
- package/php/var/is_int.js.map +0 -1
- package/php/var/is_integer.js.map +0 -1
- package/php/var/is_long.js.map +0 -1
- package/php/var/is_null.js.map +0 -1
- package/php/var/is_numeric.js.map +0 -1
- package/php/var/is_object.js.map +0 -1
- package/php/var/is_real.js.map +0 -1
- package/php/var/is_scalar.js.map +0 -1
- package/php/var/is_string.js.map +0 -1
- package/php/var/is_unicode.js.map +0 -1
- package/php/var/isset.js.map +0 -1
- package/php/var/print_r.js.map +0 -1
- package/php/var/serialize.js.map +0 -1
- package/php/var/serialize.mocha.js +0 -14
- package/php/var/serialize.mocha.js.map +0 -1
- package/php/var/strval.js.map +0 -1
- package/php/var/unserialize.js.map +0 -1
- package/php/var/var_dump.js.map +0 -1
- package/php/var/var_export.js.map +0 -1
- package/php/xdiff/index.js.map +0 -1
- package/php/xdiff/xdiff_string_diff.js.map +0 -1
- package/php/xdiff/xdiff_string_patch.js.map +0 -1
- package/php/xml/index.js.map +0 -1
- package/php/xml/utf8_decode.js.map +0 -1
- package/php/xml/utf8_encode.js.map +0 -1
- package/python/index.js.map +0 -1
- package/python/string/ascii_letters.js.map +0 -1
- package/python/string/ascii_lowercase.js.map +0 -1
- package/python/string/ascii_uppercase.js.map +0 -1
- package/python/string/capwords.js.map +0 -1
- package/python/string/index.js.map +0 -1
- package/python/string/punctuation.js.map +0 -1
- package/ruby/Math/acos.js.map +0 -1
- package/ruby/Math/index.js.map +0 -1
- package/ruby/index.js.map +0 -1
package/php/_helpers/_bc.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
// SPDX-License-Identifier: LGPL-2.1-or-later
|
|
2
|
+
// NOTE: This file is LGPL licensed, not MIT like the rest of locutus.
|
|
3
|
+
// See LICENSE file for details.
|
|
2
4
|
|
|
3
5
|
module.exports = function _bc() {
|
|
4
6
|
// discuss at: https://locutus.io/php/_helpers/_bc
|
|
@@ -9,7 +11,7 @@ module.exports = function _bc() {
|
|
|
9
11
|
// returns 1: '+'
|
|
10
12
|
|
|
11
13
|
/**
|
|
12
|
-
* BC Math Library for Javascript
|
|
14
|
+
* BC Math Library for Javascript (LGPL-2.1)
|
|
13
15
|
* Ported from the PHP5 bcmath extension source code,
|
|
14
16
|
* which uses the Libbcmath package...
|
|
15
17
|
* Copyright (C) 1991, 1992, 1993, 1994, 1997 Free Software Foundation, Inc.
|
|
@@ -23,10 +25,9 @@ module.exports = function _bc() {
|
|
|
23
25
|
* Western Washington University
|
|
24
26
|
* Bellingham, WA 98226-9062
|
|
25
27
|
*
|
|
26
|
-
* bcmath-js homepage:
|
|
28
|
+
* bcmath-js homepage: https://sourceforge.net/projects/bcmath-js/
|
|
27
29
|
*
|
|
28
|
-
* This code is covered under the LGPL
|
|
29
|
-
* Be kind and share any decent code changes.
|
|
30
|
+
* This code is covered under the LGPL-2.1 license.
|
|
30
31
|
*/
|
|
31
32
|
|
|
32
33
|
/**
|
|
@@ -54,7 +55,7 @@ module.exports = function _bc() {
|
|
|
54
55
|
* Bellingham, WA 98226-9062
|
|
55
56
|
*/
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
const Libbcmath = {
|
|
58
59
|
PLUS: '+',
|
|
59
60
|
MINUS: '-',
|
|
60
61
|
BASE: 10,
|
|
@@ -64,27 +65,27 @@ module.exports = function _bc() {
|
|
|
64
65
|
/**
|
|
65
66
|
* Basic number structure
|
|
66
67
|
*/
|
|
67
|
-
bc_num: function
|
|
68
|
-
this.n_sign = null
|
|
69
|
-
this.n_len = null
|
|
70
|
-
this.n_scale = null
|
|
68
|
+
bc_num: function () {
|
|
69
|
+
this.n_sign = null // sign
|
|
70
|
+
this.n_len = null // (int) The number of digits before the decimal point.
|
|
71
|
+
this.n_scale = null // (int) The number of digits after the decimal point.
|
|
71
72
|
// this.n_refs = null; // (int) The number of pointers to this number.
|
|
72
73
|
// this.n_text = null; // ?? Linked list for available list.
|
|
73
|
-
this.n_value = null
|
|
74
|
+
this.n_value = null // array as value, where 1.23 = [1,2,3]
|
|
74
75
|
this.toString = function () {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
tmp = this.n_value.join('')
|
|
76
|
+
let r
|
|
77
|
+
let tmp
|
|
78
|
+
tmp = this.n_value.join('')
|
|
78
79
|
|
|
79
80
|
// add minus sign (if applicable) then add the integer part
|
|
80
|
-
r = (this.n_sign === Libbcmath.PLUS ? '' : this.n_sign) + tmp.substr(0, this.n_len)
|
|
81
|
+
r = (this.n_sign === Libbcmath.PLUS ? '' : this.n_sign) + tmp.substr(0, this.n_len)
|
|
81
82
|
|
|
82
83
|
// if decimal places, add a . and the decimal part
|
|
83
84
|
if (this.n_scale > 0) {
|
|
84
|
-
r += '.' + tmp.substr(this.n_len, this.n_scale)
|
|
85
|
+
r += '.' + tmp.substr(this.n_len, this.n_scale)
|
|
85
86
|
}
|
|
86
|
-
return r
|
|
87
|
-
}
|
|
87
|
+
return r
|
|
88
|
+
}
|
|
88
89
|
},
|
|
89
90
|
|
|
90
91
|
/**
|
|
@@ -99,38 +100,38 @@ module.exports = function _bc() {
|
|
|
99
100
|
* @param {int} scaleMin
|
|
100
101
|
* @return bc_num
|
|
101
102
|
*/
|
|
102
|
-
bc_add: function
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
bc_add: function (n1, n2, scaleMin) {
|
|
104
|
+
let sum
|
|
105
|
+
let cmpRes
|
|
106
|
+
let resScale
|
|
106
107
|
|
|
107
108
|
if (n1.n_sign === n2.n_sign) {
|
|
108
|
-
sum = Libbcmath._bc_do_add(n1, n2, scaleMin)
|
|
109
|
-
sum.n_sign = n1.n_sign
|
|
109
|
+
sum = Libbcmath._bc_do_add(n1, n2, scaleMin)
|
|
110
|
+
sum.n_sign = n1.n_sign
|
|
110
111
|
} else {
|
|
111
112
|
// subtraction must be done.
|
|
112
|
-
cmpRes = Libbcmath._bc_do_compare(n1, n2, false, false)
|
|
113
|
+
cmpRes = Libbcmath._bc_do_compare(n1, n2, false, false) // Compare magnitudes.
|
|
113
114
|
switch (cmpRes) {
|
|
114
115
|
case -1:
|
|
115
116
|
// n1 is less than n2, subtract n1 from n2.
|
|
116
|
-
sum = Libbcmath._bc_do_sub(n2, n1, scaleMin)
|
|
117
|
-
sum.n_sign = n2.n_sign
|
|
118
|
-
break
|
|
117
|
+
sum = Libbcmath._bc_do_sub(n2, n1, scaleMin)
|
|
118
|
+
sum.n_sign = n2.n_sign
|
|
119
|
+
break
|
|
119
120
|
|
|
120
121
|
case 0:
|
|
121
122
|
// They are equal! return zero with the correct scale!
|
|
122
|
-
resScale = Libbcmath.MAX(scaleMin, Libbcmath.MAX(n1.n_scale, n2.n_scale))
|
|
123
|
-
sum = Libbcmath.bc_new_num(1, resScale)
|
|
124
|
-
Libbcmath.memset(sum.n_value, 0, 0, resScale + 1)
|
|
125
|
-
break
|
|
123
|
+
resScale = Libbcmath.MAX(scaleMin, Libbcmath.MAX(n1.n_scale, n2.n_scale))
|
|
124
|
+
sum = Libbcmath.bc_new_num(1, resScale)
|
|
125
|
+
Libbcmath.memset(sum.n_value, 0, 0, resScale + 1)
|
|
126
|
+
break
|
|
126
127
|
|
|
127
128
|
case 1:
|
|
128
129
|
// n2 is less than n1, subtract n2 from n1.
|
|
129
|
-
sum = Libbcmath._bc_do_sub(n1, n2, scaleMin)
|
|
130
|
-
sum.n_sign = n1.n_sign
|
|
130
|
+
sum = Libbcmath._bc_do_sub(n1, n2, scaleMin)
|
|
131
|
+
sum.n_sign = n1.n_sign
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
|
-
return sum
|
|
134
|
+
return sum
|
|
134
135
|
},
|
|
135
136
|
|
|
136
137
|
/**
|
|
@@ -139,72 +140,72 @@ module.exports = function _bc() {
|
|
|
139
140
|
* @param {bc_num} n2
|
|
140
141
|
* @return int -1, 0, 1 (n1 < n2, ===, n1 > n2)
|
|
141
142
|
*/
|
|
142
|
-
bc_compare: function
|
|
143
|
-
return Libbcmath._bc_do_compare(n1, n2, true, false)
|
|
143
|
+
bc_compare: function (n1, n2) {
|
|
144
|
+
return Libbcmath._bc_do_compare(n1, n2, true, false)
|
|
144
145
|
},
|
|
145
146
|
|
|
146
|
-
_one_mult: function
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
147
|
+
_one_mult: function (num, nPtr, size, digit, result, rPtr) {
|
|
148
|
+
let carry
|
|
149
|
+
let value // int
|
|
150
|
+
let nptr
|
|
151
|
+
let rptr // int pointers
|
|
151
152
|
if (digit === 0) {
|
|
152
|
-
Libbcmath.memset(result, 0, 0, size)
|
|
153
|
+
Libbcmath.memset(result, 0, 0, size) // memset (result, 0, size);
|
|
153
154
|
} else {
|
|
154
155
|
if (digit === 1) {
|
|
155
|
-
Libbcmath.memcpy(result, rPtr, num, nPtr, size)
|
|
156
|
+
Libbcmath.memcpy(result, rPtr, num, nPtr, size) // memcpy (result, num, size);
|
|
156
157
|
} else {
|
|
157
158
|
// Initialize
|
|
158
|
-
nptr = nPtr + size - 1
|
|
159
|
-
rptr = rPtr + size - 1
|
|
160
|
-
carry = 0
|
|
159
|
+
nptr = nPtr + size - 1 // nptr = (unsigned char *) (num+size-1);
|
|
160
|
+
rptr = rPtr + size - 1 // rptr = (unsigned char *) (result+size-1);
|
|
161
|
+
carry = 0
|
|
161
162
|
|
|
162
163
|
while (size-- > 0) {
|
|
163
|
-
value = num[nptr--] * digit + carry
|
|
164
|
-
result[rptr--] = value % Libbcmath.BASE
|
|
165
|
-
carry = Math.floor(value / Libbcmath.BASE)
|
|
164
|
+
value = num[nptr--] * digit + carry // value = *nptr-- * digit + carry;
|
|
165
|
+
result[rptr--] = value % Libbcmath.BASE // @CHECK cint //*rptr-- = value % BASE;
|
|
166
|
+
carry = Math.floor(value / Libbcmath.BASE) // @CHECK cint //carry = value / BASE;
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
if (carry !== 0) {
|
|
169
|
-
result[rptr] = carry
|
|
170
|
+
result[rptr] = carry
|
|
170
171
|
}
|
|
171
172
|
}
|
|
172
173
|
}
|
|
173
174
|
},
|
|
174
175
|
|
|
175
|
-
bc_divide: function
|
|
176
|
+
bc_divide: function (n1, n2, scale) {
|
|
176
177
|
// var quot // bc_num return
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
178
|
+
let qval // bc_num
|
|
179
|
+
let num1
|
|
180
|
+
let num2 // string
|
|
181
|
+
let ptr1
|
|
182
|
+
let ptr2
|
|
183
|
+
let n2ptr
|
|
184
|
+
let qptr // int pointers
|
|
185
|
+
let scale1
|
|
186
|
+
let val // int
|
|
187
|
+
let len1
|
|
188
|
+
let len2
|
|
189
|
+
let scale2
|
|
190
|
+
let qdigits
|
|
191
|
+
let extra
|
|
192
|
+
let count // int
|
|
193
|
+
let qdig
|
|
194
|
+
let qguess
|
|
195
|
+
let borrow
|
|
196
|
+
let carry // int
|
|
197
|
+
let mval // string
|
|
198
|
+
let zero // char
|
|
199
|
+
let norm // int
|
|
199
200
|
// var ptrs // return object from one_mul
|
|
200
201
|
// Test for divide by zero. (return failure)
|
|
201
202
|
if (Libbcmath.bc_is_zero(n2)) {
|
|
202
|
-
return -1
|
|
203
|
+
return -1
|
|
203
204
|
}
|
|
204
205
|
|
|
205
206
|
// Test for zero divide by anything (return zero)
|
|
206
207
|
if (Libbcmath.bc_is_zero(n1)) {
|
|
207
|
-
return Libbcmath.bc_new_num(1, scale)
|
|
208
|
+
return Libbcmath.bc_new_num(1, scale)
|
|
208
209
|
}
|
|
209
210
|
|
|
210
211
|
/* Test for n1 equals n2 (return 1 as n1 nor n2 are zero)
|
|
@@ -220,12 +221,12 @@ module.exports = function _bc() {
|
|
|
220
221
|
// (ie bc_is_zero - add bc_is_one function)
|
|
221
222
|
if (n2.n_scale === 0) {
|
|
222
223
|
if (n2.n_len === 1 && n2.n_value[0] === 1) {
|
|
223
|
-
qval = Libbcmath.bc_new_num(n1.n_len, scale)
|
|
224
|
-
qval.n_sign = n1.n_sign === n2.n_sign ? Libbcmath.PLUS : Libbcmath.MINUS
|
|
224
|
+
qval = Libbcmath.bc_new_num(n1.n_len, scale) // qval = bc_new_num (n1->n_len, scale);
|
|
225
|
+
qval.n_sign = n1.n_sign === n2.n_sign ? Libbcmath.PLUS : Libbcmath.MINUS
|
|
225
226
|
// memset (&qval->n_value[n1->n_len],0,scale):
|
|
226
|
-
Libbcmath.memset(qval.n_value, n1.n_len, 0, scale)
|
|
227
|
+
Libbcmath.memset(qval.n_value, n1.n_len, 0, scale)
|
|
227
228
|
// memcpy (qval->n_value, n1->n_value, n1->n_len + MIN(n1->n_scale,scale)):
|
|
228
|
-
Libbcmath.memcpy(qval.n_value, 0, n1.n_value, 0, n1.n_len + Libbcmath.MIN(n1.n_scale, scale))
|
|
229
|
+
Libbcmath.memcpy(qval.n_value, 0, n1.n_value, 0, n1.n_len + Libbcmath.MIN(n1.n_scale, scale))
|
|
229
230
|
// can we return here? not in c src, but can't see why-not.
|
|
230
231
|
// return qval;
|
|
231
232
|
}
|
|
@@ -233,71 +234,71 @@ module.exports = function _bc() {
|
|
|
233
234
|
|
|
234
235
|
/* Set up the divide. Move the decimal point on n1 by n2's scale.
|
|
235
236
|
Remember, zeros on the end of num2 are wasted effort for dividing. */
|
|
236
|
-
scale2 = n2.n_scale
|
|
237
|
-
n2ptr = n2.n_len + scale2 - 1
|
|
237
|
+
scale2 = n2.n_scale // scale2 = n2->n_scale;
|
|
238
|
+
n2ptr = n2.n_len + scale2 - 1 // n2ptr = (unsigned char *) n2.n_value+n2.n_len+scale2-1;
|
|
238
239
|
while (scale2 > 0 && n2.n_value[n2ptr--] === 0) {
|
|
239
|
-
scale2
|
|
240
|
+
scale2--
|
|
240
241
|
}
|
|
241
242
|
|
|
242
|
-
len1 = n1.n_len + scale2
|
|
243
|
-
scale1 = n1.n_scale - scale2
|
|
243
|
+
len1 = n1.n_len + scale2
|
|
244
|
+
scale1 = n1.n_scale - scale2
|
|
244
245
|
if (scale1 < scale) {
|
|
245
|
-
extra = scale - scale1
|
|
246
|
+
extra = scale - scale1
|
|
246
247
|
} else {
|
|
247
|
-
extra = 0
|
|
248
|
+
extra = 0
|
|
248
249
|
}
|
|
249
250
|
|
|
250
251
|
// num1 = (unsigned char *) safe_emalloc (1, n1.n_len+n1.n_scale, extra+2):
|
|
251
|
-
num1 = Libbcmath.safe_emalloc(1, n1.n_len + n1.n_scale, extra + 2)
|
|
252
|
+
num1 = Libbcmath.safe_emalloc(1, n1.n_len + n1.n_scale, extra + 2)
|
|
252
253
|
if (num1 === null) {
|
|
253
|
-
Libbcmath.bc_out_of_memory()
|
|
254
|
+
Libbcmath.bc_out_of_memory()
|
|
254
255
|
}
|
|
255
256
|
// memset (num1, 0, n1->n_len+n1->n_scale+extra+2):
|
|
256
|
-
Libbcmath.memset(num1, 0, 0, n1.n_len + n1.n_scale + extra + 2)
|
|
257
|
+
Libbcmath.memset(num1, 0, 0, n1.n_len + n1.n_scale + extra + 2)
|
|
257
258
|
// memcpy (num1+1, n1.n_value, n1.n_len+n1.n_scale):
|
|
258
|
-
Libbcmath.memcpy(num1, 1, n1.n_value, 0, n1.n_len + n1.n_scale)
|
|
259
|
+
Libbcmath.memcpy(num1, 1, n1.n_value, 0, n1.n_len + n1.n_scale)
|
|
259
260
|
// len2 = n2->n_len + scale2:
|
|
260
|
-
len2 = n2.n_len + scale2
|
|
261
|
+
len2 = n2.n_len + scale2
|
|
261
262
|
// num2 = (unsigned char *) safe_emalloc (1, len2, 1):
|
|
262
|
-
num2 = Libbcmath.safe_emalloc(1, len2, 1)
|
|
263
|
+
num2 = Libbcmath.safe_emalloc(1, len2, 1)
|
|
263
264
|
if (num2 === null) {
|
|
264
|
-
Libbcmath.bc_out_of_memory()
|
|
265
|
+
Libbcmath.bc_out_of_memory()
|
|
265
266
|
}
|
|
266
267
|
// memcpy (num2, n2.n_value, len2):
|
|
267
|
-
Libbcmath.memcpy(num2, 0, n2.n_value, 0, len2)
|
|
268
|
+
Libbcmath.memcpy(num2, 0, n2.n_value, 0, len2)
|
|
268
269
|
// *(num2+len2) = 0:
|
|
269
|
-
num2[len2] = 0
|
|
270
|
+
num2[len2] = 0
|
|
270
271
|
// n2ptr = num2:
|
|
271
|
-
n2ptr = 0
|
|
272
|
+
n2ptr = 0
|
|
272
273
|
// while (*n2ptr === 0):
|
|
273
274
|
while (num2[n2ptr] === 0) {
|
|
274
|
-
n2ptr
|
|
275
|
-
len2
|
|
275
|
+
n2ptr++
|
|
276
|
+
len2--
|
|
276
277
|
}
|
|
277
278
|
|
|
278
279
|
// Calculate the number of quotient digits.
|
|
279
280
|
if (len2 > len1 + scale) {
|
|
280
|
-
qdigits = scale + 1
|
|
281
|
-
zero = true
|
|
281
|
+
qdigits = scale + 1
|
|
282
|
+
zero = true
|
|
282
283
|
} else {
|
|
283
|
-
zero = false
|
|
284
|
+
zero = false
|
|
284
285
|
if (len2 > len1) {
|
|
285
|
-
qdigits = scale + 1
|
|
286
|
+
qdigits = scale + 1 // One for the zero integer part.
|
|
286
287
|
} else {
|
|
287
|
-
qdigits = len1 - len2 + scale + 1
|
|
288
|
+
qdigits = len1 - len2 + scale + 1
|
|
288
289
|
}
|
|
289
290
|
}
|
|
290
291
|
|
|
291
292
|
// Allocate and zero the storage for the quotient.
|
|
292
293
|
// qval = bc_new_num (qdigits-scale,scale);
|
|
293
|
-
qval = Libbcmath.bc_new_num(qdigits - scale, scale)
|
|
294
|
+
qval = Libbcmath.bc_new_num(qdigits - scale, scale)
|
|
294
295
|
// memset (qval->n_value, 0, qdigits);
|
|
295
|
-
Libbcmath.memset(qval.n_value, 0, 0, qdigits)
|
|
296
|
+
Libbcmath.memset(qval.n_value, 0, 0, qdigits)
|
|
296
297
|
// Allocate storage for the temporary storage mval.
|
|
297
298
|
// mval = (unsigned char *) safe_emalloc (1, len2, 1);
|
|
298
|
-
mval = Libbcmath.safe_emalloc(1, len2, 1)
|
|
299
|
+
mval = Libbcmath.safe_emalloc(1, len2, 1)
|
|
299
300
|
if (mval === null) {
|
|
300
|
-
Libbcmath.bc_out_of_memory()
|
|
301
|
+
Libbcmath.bc_out_of_memory()
|
|
301
302
|
}
|
|
302
303
|
|
|
303
304
|
// Now for the full divide algorithm.
|
|
@@ -305,121 +306,127 @@ module.exports = function _bc() {
|
|
|
305
306
|
// Normalize
|
|
306
307
|
// norm = Libbcmath.cint(10 / (Libbcmath.cint(n2.n_value[n2ptr]) + 1));
|
|
307
308
|
// norm = 10 / ((int)*n2ptr + 1)
|
|
308
|
-
norm = Math.floor(10 / (n2.n_value[n2ptr] + 1))
|
|
309
|
+
norm = Math.floor(10 / (n2.n_value[n2ptr] + 1)) // norm = 10 / ((int)*n2ptr + 1);
|
|
309
310
|
if (norm !== 1) {
|
|
310
311
|
// Libbcmath._one_mult(num1, len1+scale1+extra+1, norm, num1);
|
|
311
|
-
Libbcmath._one_mult(num1, 0, len1 + scale1 + extra + 1, norm, num1, 0)
|
|
312
|
+
Libbcmath._one_mult(num1, 0, len1 + scale1 + extra + 1, norm, num1, 0)
|
|
312
313
|
// Libbcmath._one_mult(n2ptr, len2, norm, n2ptr);
|
|
313
|
-
Libbcmath._one_mult(n2.n_value, n2ptr, len2, norm, n2.n_value, n2ptr)
|
|
314
|
+
Libbcmath._one_mult(n2.n_value, n2ptr, len2, norm, n2.n_value, n2ptr)
|
|
314
315
|
// @todo: Check: Is the pointer affected by the call? if so,
|
|
315
316
|
// maybe need to adjust points on return?
|
|
316
317
|
}
|
|
317
318
|
|
|
318
319
|
// Initialize divide loop.
|
|
319
|
-
qdig = 0
|
|
320
|
+
qdig = 0
|
|
320
321
|
if (len2 > len1) {
|
|
321
|
-
qptr = len2 - len1
|
|
322
|
+
qptr = len2 - len1 // qptr = (unsigned char *) qval.n_value+len2-len1;
|
|
322
323
|
} else {
|
|
323
|
-
qptr = 0
|
|
324
|
+
qptr = 0 // qptr = (unsigned char *) qval.n_value;
|
|
324
325
|
}
|
|
325
326
|
|
|
326
327
|
// Loop
|
|
327
328
|
while (qdig <= len1 + scale - len2) {
|
|
328
329
|
// Calculate the quotient digit guess.
|
|
329
330
|
if (n2.n_value[n2ptr] === num1[qdig]) {
|
|
330
|
-
qguess = 9
|
|
331
|
+
qguess = 9
|
|
331
332
|
} else {
|
|
332
|
-
qguess = Math.floor((num1[qdig] * 10 + num1[qdig + 1]) / n2.n_value[n2ptr])
|
|
333
|
+
qguess = Math.floor((num1[qdig] * 10 + num1[qdig + 1]) / n2.n_value[n2ptr])
|
|
333
334
|
}
|
|
334
335
|
// Test qguess.
|
|
335
336
|
|
|
336
|
-
if (
|
|
337
|
-
qguess
|
|
337
|
+
if (
|
|
338
|
+
n2.n_value[n2ptr + 1] * qguess >
|
|
339
|
+
(num1[qdig] * 10 + num1[qdig + 1] - n2.n_value[n2ptr] * qguess) * 10 + num1[qdig + 2]
|
|
340
|
+
) {
|
|
341
|
+
qguess--
|
|
338
342
|
// And again.
|
|
339
|
-
if (
|
|
340
|
-
qguess
|
|
343
|
+
if (
|
|
344
|
+
n2.n_value[n2ptr + 1] * qguess >
|
|
345
|
+
(num1[qdig] * 10 + num1[qdig + 1] - n2.n_value[n2ptr] * qguess) * 10 + num1[qdig + 2]
|
|
346
|
+
) {
|
|
347
|
+
qguess--
|
|
341
348
|
}
|
|
342
349
|
}
|
|
343
350
|
|
|
344
351
|
// Multiply and subtract.
|
|
345
|
-
borrow = 0
|
|
352
|
+
borrow = 0
|
|
346
353
|
if (qguess !== 0) {
|
|
347
|
-
mval[0] = 0
|
|
354
|
+
mval[0] = 0 //* mval = 0; // @CHECK is this to fix ptr2 < 0?
|
|
348
355
|
// _one_mult (n2ptr, len2, qguess, mval+1); // @CHECK
|
|
349
|
-
Libbcmath._one_mult(n2.n_value, n2ptr, len2, qguess, mval, 1)
|
|
350
|
-
ptr1 = qdig + len2
|
|
351
|
-
ptr2 = len2
|
|
356
|
+
Libbcmath._one_mult(n2.n_value, n2ptr, len2, qguess, mval, 1)
|
|
357
|
+
ptr1 = qdig + len2 // (unsigned char *) num1+qdig+len2;
|
|
358
|
+
ptr2 = len2 // (unsigned char *) mval+len2;
|
|
352
359
|
// @todo: CHECK: Does a negative pointer return null?
|
|
353
360
|
// ptr2 can be < 0 here as ptr1 = len2, thus count < len2+1 will always fail ?
|
|
354
361
|
for (count = 0; count < len2 + 1; count++) {
|
|
355
362
|
if (ptr2 < 0) {
|
|
356
363
|
// val = Libbcmath.cint(num1[ptr1]) - 0 - borrow;
|
|
357
364
|
// val = (int) *ptr1 - (int) *ptr2-- - borrow;
|
|
358
|
-
val = num1[ptr1] - 0 - borrow
|
|
365
|
+
val = num1[ptr1] - 0 - borrow // val = (int) *ptr1 - (int) *ptr2-- - borrow;
|
|
359
366
|
} else {
|
|
360
367
|
// val = Libbcmath.cint(num1[ptr1]) - Libbcmath.cint(mval[ptr2--]) - borrow;
|
|
361
368
|
// val = (int) *ptr1 - (int) *ptr2-- - borrow;
|
|
362
369
|
// val = (int) *ptr1 - (int) *ptr2-- - borrow;
|
|
363
|
-
val = num1[ptr1] - mval[ptr2--] - borrow
|
|
370
|
+
val = num1[ptr1] - mval[ptr2--] - borrow
|
|
364
371
|
}
|
|
365
372
|
if (val < 0) {
|
|
366
|
-
val += 10
|
|
367
|
-
borrow = 1
|
|
373
|
+
val += 10
|
|
374
|
+
borrow = 1
|
|
368
375
|
} else {
|
|
369
|
-
borrow = 0
|
|
376
|
+
borrow = 0
|
|
370
377
|
}
|
|
371
|
-
num1[ptr1--] = val
|
|
378
|
+
num1[ptr1--] = val
|
|
372
379
|
}
|
|
373
380
|
}
|
|
374
381
|
|
|
375
382
|
// Test for negative result.
|
|
376
383
|
if (borrow === 1) {
|
|
377
|
-
qguess
|
|
378
|
-
ptr1 = qdig + len2
|
|
379
|
-
ptr2 = len2 - 1
|
|
380
|
-
carry = 0
|
|
384
|
+
qguess--
|
|
385
|
+
ptr1 = qdig + len2 // (unsigned char *) num1+qdig+len2;
|
|
386
|
+
ptr2 = len2 - 1 // (unsigned char *) n2ptr+len2-1;
|
|
387
|
+
carry = 0
|
|
381
388
|
for (count = 0; count < len2; count++) {
|
|
382
389
|
if (ptr2 < 0) {
|
|
383
390
|
// val = Libbcmath.cint(num1[ptr1]) + 0 + carry;
|
|
384
391
|
// val = (int) *ptr1 + (int) *ptr2-- + carry;
|
|
385
392
|
// val = (int) *ptr1 + (int) *ptr2-- + carry;
|
|
386
|
-
val = num1[ptr1] + 0 + carry
|
|
393
|
+
val = num1[ptr1] + 0 + carry
|
|
387
394
|
} else {
|
|
388
395
|
// val = Libbcmath.cint(num1[ptr1]) + Libbcmath.cint(n2.n_value[ptr2--]) + carry;
|
|
389
396
|
// val = (int) *ptr1 + (int) *ptr2-- + carry;
|
|
390
397
|
// val = (int) *ptr1 + (int) *ptr2-- + carry;
|
|
391
|
-
val = num1[ptr1] + n2.n_value[ptr2--] + carry
|
|
398
|
+
val = num1[ptr1] + n2.n_value[ptr2--] + carry
|
|
392
399
|
}
|
|
393
400
|
if (val > 9) {
|
|
394
|
-
val -= 10
|
|
395
|
-
carry = 1
|
|
401
|
+
val -= 10
|
|
402
|
+
carry = 1
|
|
396
403
|
} else {
|
|
397
|
-
carry = 0
|
|
404
|
+
carry = 0
|
|
398
405
|
}
|
|
399
|
-
num1[ptr1--] = val
|
|
406
|
+
num1[ptr1--] = val //* ptr1-- = val;
|
|
400
407
|
}
|
|
401
408
|
if (carry === 1) {
|
|
402
409
|
// num1[ptr1] = Libbcmath.cint((num1[ptr1] + 1) % 10);
|
|
403
410
|
// *ptr1 = (*ptr1 + 1) % 10; // @CHECK
|
|
404
411
|
// *ptr1 = (*ptr1 + 1) % 10; // @CHECK
|
|
405
|
-
num1[ptr1] = (num1[ptr1] + 1) % 10
|
|
412
|
+
num1[ptr1] = (num1[ptr1] + 1) % 10
|
|
406
413
|
}
|
|
407
414
|
}
|
|
408
415
|
|
|
409
416
|
// We now know the quotient digit.
|
|
410
|
-
qval.n_value[qptr++] = qguess
|
|
411
|
-
qdig
|
|
417
|
+
qval.n_value[qptr++] = qguess //* qptr++ = qguess;
|
|
418
|
+
qdig++
|
|
412
419
|
}
|
|
413
420
|
}
|
|
414
421
|
|
|
415
422
|
// Clean up and return the number.
|
|
416
|
-
qval.n_sign = n1.n_sign === n2.n_sign ? Libbcmath.PLUS : Libbcmath.MINUS
|
|
423
|
+
qval.n_sign = n1.n_sign === n2.n_sign ? Libbcmath.PLUS : Libbcmath.MINUS
|
|
417
424
|
if (Libbcmath.bc_is_zero(qval)) {
|
|
418
|
-
qval.n_sign = Libbcmath.PLUS
|
|
425
|
+
qval.n_sign = Libbcmath.PLUS
|
|
419
426
|
}
|
|
420
|
-
Libbcmath._bc_rm_leading_zeros(qval)
|
|
427
|
+
Libbcmath._bc_rm_leading_zeros(qval)
|
|
421
428
|
|
|
422
|
-
return qval
|
|
429
|
+
return qval
|
|
423
430
|
|
|
424
431
|
// return 0; // Everything is OK.
|
|
425
432
|
},
|
|
@@ -429,161 +436,159 @@ module.exports = function _bc() {
|
|
|
429
436
|
// #define MUL_SMALL_DIGITS mul_base_digits/4
|
|
430
437
|
|
|
431
438
|
/* The multiply routine. N2 times N1 is put int PROD with the scale of
|
|
432
|
-
|
|
433
|
-
|
|
439
|
+
the result being MIN(N2 scale+N1 scale, MAX (SCALE, N2 scale, N1 scale)).
|
|
440
|
+
*/
|
|
434
441
|
/**
|
|
435
442
|
* @param n1 bc_num
|
|
436
443
|
* @param n2 bc_num
|
|
437
444
|
* @param scale [int] optional
|
|
438
445
|
*/
|
|
439
|
-
bc_multiply: function
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
446
|
+
bc_multiply: function (n1, n2, scale) {
|
|
447
|
+
let pval // bc_num
|
|
448
|
+
let len1
|
|
449
|
+
let len2 // int
|
|
450
|
+
let fullScale
|
|
451
|
+
let prodScale // int
|
|
445
452
|
// Initialize things.
|
|
446
|
-
len1 = n1.n_len + n1.n_scale
|
|
447
|
-
len2 = n2.n_len + n2.n_scale
|
|
448
|
-
fullScale = n1.n_scale + n2.n_scale
|
|
449
|
-
prodScale = Libbcmath.MIN(fullScale, Libbcmath.MAX(scale, Libbcmath.MAX(n1.n_scale, n2.n_scale)))
|
|
453
|
+
len1 = n1.n_len + n1.n_scale
|
|
454
|
+
len2 = n2.n_len + n2.n_scale
|
|
455
|
+
fullScale = n1.n_scale + n2.n_scale
|
|
456
|
+
prodScale = Libbcmath.MIN(fullScale, Libbcmath.MAX(scale, Libbcmath.MAX(n1.n_scale, n2.n_scale)))
|
|
450
457
|
|
|
451
458
|
// pval = Libbcmath.bc_init_num(); // allow pass by ref
|
|
452
459
|
// Do the multiply
|
|
453
|
-
pval = Libbcmath._bc_rec_mul(n1, len1, n2, len2, fullScale)
|
|
460
|
+
pval = Libbcmath._bc_rec_mul(n1, len1, n2, len2, fullScale)
|
|
454
461
|
|
|
455
462
|
// Assign to prod and clean up the number.
|
|
456
|
-
pval.n_sign = n1.n_sign === n2.n_sign ? Libbcmath.PLUS : Libbcmath.MINUS
|
|
463
|
+
pval.n_sign = n1.n_sign === n2.n_sign ? Libbcmath.PLUS : Libbcmath.MINUS
|
|
457
464
|
// pval.n_value = pval.nPtr;
|
|
458
|
-
pval.n_len = len2 + len1 + 1 - fullScale
|
|
459
|
-
pval.n_scale = prodScale
|
|
460
|
-
Libbcmath._bc_rm_leading_zeros(pval)
|
|
465
|
+
pval.n_len = len2 + len1 + 1 - fullScale
|
|
466
|
+
pval.n_scale = prodScale
|
|
467
|
+
Libbcmath._bc_rm_leading_zeros(pval)
|
|
461
468
|
if (Libbcmath.bc_is_zero(pval)) {
|
|
462
|
-
pval.n_sign = Libbcmath.PLUS
|
|
469
|
+
pval.n_sign = Libbcmath.PLUS
|
|
463
470
|
}
|
|
464
471
|
// bc_free_num (prod);
|
|
465
|
-
return pval
|
|
472
|
+
return pval
|
|
466
473
|
},
|
|
467
474
|
|
|
468
|
-
new_sub_num: function
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
temp.
|
|
473
|
-
temp.
|
|
474
|
-
temp.
|
|
475
|
-
temp
|
|
476
|
-
Libbcmath.memcpy(temp.n_value, 0, value, ptr, length + scale);
|
|
477
|
-
return temp;
|
|
475
|
+
new_sub_num: function (length, scale, value, ptr = 0) {
|
|
476
|
+
const temp = new Libbcmath.bc_num()
|
|
477
|
+
temp.n_sign = Libbcmath.PLUS
|
|
478
|
+
temp.n_len = length
|
|
479
|
+
temp.n_scale = scale
|
|
480
|
+
temp.n_value = Libbcmath.safe_emalloc(1, length + scale, 0)
|
|
481
|
+
Libbcmath.memcpy(temp.n_value, 0, value, ptr, length + scale)
|
|
482
|
+
return temp
|
|
478
483
|
},
|
|
479
484
|
|
|
480
|
-
_bc_simp_mul: function
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
prodlen = n1len + n2len + 1
|
|
491
|
-
|
|
492
|
-
prod = Libbcmath.bc_new_num(prodlen, 0)
|
|
493
|
-
|
|
494
|
-
n1end = n1len - 1
|
|
495
|
-
n2end = n2len - 1
|
|
496
|
-
pvptr = prodlen - 1
|
|
497
|
-
sum = 0
|
|
485
|
+
_bc_simp_mul: function (n1, n1len, n2, n2len, fullScale) {
|
|
486
|
+
let prod // bc_num
|
|
487
|
+
let n1ptr
|
|
488
|
+
let n2ptr
|
|
489
|
+
let pvptr // char *n1ptr, *n2ptr, *pvptr;
|
|
490
|
+
let n1end
|
|
491
|
+
let n2end // char *n1end, *n2end; // To the end of n1 and n2.
|
|
492
|
+
let indx
|
|
493
|
+
let sum
|
|
494
|
+
let prodlen // int indx, sum, prodlen;
|
|
495
|
+
prodlen = n1len + n2len + 1
|
|
496
|
+
|
|
497
|
+
prod = Libbcmath.bc_new_num(prodlen, 0)
|
|
498
|
+
|
|
499
|
+
n1end = n1len - 1 // (char *) (n1->n_value + n1len - 1);
|
|
500
|
+
n2end = n2len - 1 // (char *) (n2->n_value + n2len - 1);
|
|
501
|
+
pvptr = prodlen - 1 // (char *) ((*prod)->n_value + prodlen - 1);
|
|
502
|
+
sum = 0
|
|
498
503
|
|
|
499
504
|
// Here is the loop...
|
|
500
505
|
for (indx = 0; indx < prodlen - 1; indx++) {
|
|
501
506
|
// (char *) (n1end - MAX(0, indx-n2len+1));
|
|
502
|
-
n1ptr = n1end - Libbcmath.MAX(0, indx - n2len + 1)
|
|
507
|
+
n1ptr = n1end - Libbcmath.MAX(0, indx - n2len + 1)
|
|
503
508
|
// (char *) (n2end - MIN(indx, n2len-1));
|
|
504
|
-
n2ptr = n2end - Libbcmath.MIN(indx, n2len - 1)
|
|
509
|
+
n2ptr = n2end - Libbcmath.MIN(indx, n2len - 1)
|
|
505
510
|
while (n1ptr >= 0 && n2ptr <= n2end) {
|
|
506
511
|
// sum += *n1ptr-- * *n2ptr++;
|
|
507
|
-
sum += n1.n_value[n1ptr--] * n2.n_value[n2ptr++]
|
|
512
|
+
sum += n1.n_value[n1ptr--] * n2.n_value[n2ptr++]
|
|
508
513
|
}
|
|
509
514
|
//* pvptr-- = sum % BASE;
|
|
510
|
-
prod.n_value[pvptr--] = Math.floor(sum % Libbcmath.BASE)
|
|
511
|
-
sum = Math.floor(sum / Libbcmath.BASE)
|
|
515
|
+
prod.n_value[pvptr--] = Math.floor(sum % Libbcmath.BASE)
|
|
516
|
+
sum = Math.floor(sum / Libbcmath.BASE) // sum = sum / BASE;
|
|
512
517
|
}
|
|
513
|
-
prod.n_value[pvptr] = sum
|
|
514
|
-
return prod
|
|
518
|
+
prod.n_value[pvptr] = sum //* pvptr = sum;
|
|
519
|
+
return prod
|
|
515
520
|
},
|
|
516
521
|
|
|
517
522
|
/* A special adder/subtractor for the recursive divide and conquer
|
|
518
523
|
multiply algorithm. Note: if sub is called, accum must
|
|
519
524
|
be larger that what is being subtracted. Also, accum and val
|
|
520
525
|
must have n_scale = 0. (e.g. they must look like integers. *) */
|
|
521
|
-
_bc_shift_addsub: function
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
count = val.n_len
|
|
526
|
+
_bc_shift_addsub: function (accum, val, shift, sub) {
|
|
527
|
+
let accp
|
|
528
|
+
let valp // signed char *accp, *valp;
|
|
529
|
+
let count
|
|
530
|
+
let carry // int count, carry;
|
|
531
|
+
count = val.n_len
|
|
527
532
|
if (val.n_value[0] === 0) {
|
|
528
|
-
count
|
|
533
|
+
count--
|
|
529
534
|
}
|
|
530
535
|
|
|
531
536
|
// assert (accum->n_len+accum->n_scale >= shift+count);
|
|
532
537
|
if (accum.n_len + accum.n_scale < shift + count) {
|
|
533
|
-
throw new Error('len + scale < shift + count')
|
|
538
|
+
throw new Error('len + scale < shift + count') // ?? I think that's what assert does :)
|
|
534
539
|
}
|
|
535
540
|
|
|
536
541
|
// Set up pointers and others
|
|
537
542
|
// (signed char *)(accum->n_value + accum->n_len + accum->n_scale - shift - 1);
|
|
538
|
-
accp = accum.n_len + accum.n_scale - shift - 1
|
|
539
|
-
valp = val.n_len - 1
|
|
540
|
-
carry = 0
|
|
543
|
+
accp = accum.n_len + accum.n_scale - shift - 1
|
|
544
|
+
valp = val.n_len - 1 // (signed char *)(val->n_value + val->n_len - 1);
|
|
545
|
+
carry = 0
|
|
541
546
|
if (sub) {
|
|
542
547
|
// Subtraction, carry is really borrow.
|
|
543
548
|
while (count--) {
|
|
544
|
-
accum.n_value[accp] -= val.n_value[valp--] + carry
|
|
549
|
+
accum.n_value[accp] -= val.n_value[valp--] + carry //* accp -= *valp-- + carry;
|
|
545
550
|
if (accum.n_value[accp] < 0) {
|
|
546
551
|
// if (*accp < 0)
|
|
547
|
-
carry = 1
|
|
548
|
-
accum.n_value[accp--] += Libbcmath.BASE
|
|
552
|
+
carry = 1
|
|
553
|
+
accum.n_value[accp--] += Libbcmath.BASE //* accp-- += BASE;
|
|
549
554
|
} else {
|
|
550
|
-
carry = 0
|
|
551
|
-
accp
|
|
555
|
+
carry = 0
|
|
556
|
+
accp--
|
|
552
557
|
}
|
|
553
558
|
}
|
|
554
559
|
while (carry) {
|
|
555
|
-
accum.n_value[accp] -= carry
|
|
560
|
+
accum.n_value[accp] -= carry //* accp -= carry;
|
|
556
561
|
if (accum.n_value[accp] < 0) {
|
|
557
562
|
// if (*accp < 0)
|
|
558
|
-
accum.n_value[accp--] += Libbcmath.BASE
|
|
563
|
+
accum.n_value[accp--] += Libbcmath.BASE // *accp-- += BASE;
|
|
559
564
|
} else {
|
|
560
|
-
carry = 0
|
|
565
|
+
carry = 0
|
|
561
566
|
}
|
|
562
567
|
}
|
|
563
568
|
} else {
|
|
564
569
|
// Addition
|
|
565
570
|
while (count--) {
|
|
566
|
-
accum.n_value[accp] += val.n_value[valp--] + carry
|
|
571
|
+
accum.n_value[accp] += val.n_value[valp--] + carry //* accp += *valp-- + carry;
|
|
567
572
|
if (accum.n_value[accp] > Libbcmath.BASE - 1) {
|
|
568
573
|
// if (*accp > (BASE-1))
|
|
569
|
-
carry = 1
|
|
570
|
-
accum.n_value[accp--] -= Libbcmath.BASE
|
|
574
|
+
carry = 1
|
|
575
|
+
accum.n_value[accp--] -= Libbcmath.BASE //* accp-- -= BASE;
|
|
571
576
|
} else {
|
|
572
|
-
carry = 0
|
|
573
|
-
accp
|
|
577
|
+
carry = 0
|
|
578
|
+
accp--
|
|
574
579
|
}
|
|
575
580
|
}
|
|
576
581
|
while (carry) {
|
|
577
|
-
accum.n_value[accp] += carry
|
|
582
|
+
accum.n_value[accp] += carry //* accp += carry;
|
|
578
583
|
if (accum.n_value[accp] > Libbcmath.BASE - 1) {
|
|
579
584
|
// if (*accp > (BASE-1))
|
|
580
|
-
accum.n_value[accp--] -= Libbcmath.BASE
|
|
585
|
+
accum.n_value[accp--] -= Libbcmath.BASE //* accp-- -= BASE;
|
|
581
586
|
} else {
|
|
582
|
-
carry = 0
|
|
587
|
+
carry = 0
|
|
583
588
|
}
|
|
584
589
|
}
|
|
585
590
|
}
|
|
586
|
-
return true
|
|
591
|
+
return true // accum is the pass-by-reference return
|
|
587
592
|
},
|
|
588
593
|
|
|
589
594
|
/* Recursive divide and conquer multiply algorithm.
|
|
@@ -591,101 +596,106 @@ module.exports = function _bc() {
|
|
|
591
596
|
Let u = u0 + u1*(b^n)
|
|
592
597
|
Let v = v0 + v1*(b^n)
|
|
593
598
|
Then uv = (B^2n+B^n)*u1*v1 + B^n*(u1-u0)*(v0-v1) + (B^n+1)*u0*v0
|
|
594
|
-
|
|
599
|
+
|
|
600
|
+
B is the base of storage, number of digits in u1,u0 close to equal.
|
|
595
601
|
*/
|
|
596
|
-
_bc_rec_mul: function
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
+
_bc_rec_mul: function (u, ulen, v, vlen, fullScale) {
|
|
603
|
+
let prod // @return
|
|
604
|
+
let u0
|
|
605
|
+
let u1
|
|
606
|
+
let v0
|
|
607
|
+
let v1 // bc_num
|
|
602
608
|
// var u0len,
|
|
603
609
|
// var v0len // int
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
610
|
+
let m1
|
|
611
|
+
let m2
|
|
612
|
+
let m3
|
|
613
|
+
let d1
|
|
614
|
+
let d2 // bc_num
|
|
615
|
+
let n
|
|
616
|
+
let prodlen
|
|
617
|
+
let m1zero // int
|
|
618
|
+
let d1len
|
|
619
|
+
let d2len // int
|
|
614
620
|
// Base case?
|
|
615
|
-
if (
|
|
616
|
-
|
|
621
|
+
if (
|
|
622
|
+
ulen + vlen < Libbcmath.MUL_BASE_DIGITS ||
|
|
623
|
+
ulen < Libbcmath.MUL_SMALL_DIGITS ||
|
|
624
|
+
vlen < Libbcmath.MUL_SMALL_DIGITS
|
|
625
|
+
) {
|
|
626
|
+
return Libbcmath._bc_simp_mul(u, ulen, v, vlen, fullScale)
|
|
617
627
|
}
|
|
618
628
|
|
|
619
629
|
// Calculate n -- the u and v split point in digits.
|
|
620
|
-
n = Math.floor((Libbcmath.MAX(ulen, vlen) + 1) / 2)
|
|
630
|
+
n = Math.floor((Libbcmath.MAX(ulen, vlen) + 1) / 2)
|
|
621
631
|
|
|
622
632
|
// Split u and v.
|
|
623
633
|
if (ulen < n) {
|
|
624
|
-
u1 = Libbcmath.bc_init_num()
|
|
625
|
-
u0 = Libbcmath.new_sub_num(ulen, 0, u.n_value)
|
|
634
|
+
u1 = Libbcmath.bc_init_num() // u1 = bc_copy_num (BCG(_zero_));
|
|
635
|
+
u0 = Libbcmath.new_sub_num(ulen, 0, u.n_value)
|
|
626
636
|
} else {
|
|
627
|
-
u1 = Libbcmath.new_sub_num(ulen - n, 0, u.n_value)
|
|
628
|
-
u0 = Libbcmath.new_sub_num(n, 0, u.n_value, ulen - n)
|
|
637
|
+
u1 = Libbcmath.new_sub_num(ulen - n, 0, u.n_value)
|
|
638
|
+
u0 = Libbcmath.new_sub_num(n, 0, u.n_value, ulen - n)
|
|
629
639
|
}
|
|
630
640
|
if (vlen < n) {
|
|
631
|
-
v1 = Libbcmath.bc_init_num()
|
|
632
|
-
v0 = Libbcmath.new_sub_num(vlen, 0, v.n_value)
|
|
641
|
+
v1 = Libbcmath.bc_init_num() // bc_copy_num (BCG(_zero_));
|
|
642
|
+
v0 = Libbcmath.new_sub_num(vlen, 0, v.n_value)
|
|
633
643
|
} else {
|
|
634
|
-
v1 = Libbcmath.new_sub_num(vlen - n, 0, v.n_value)
|
|
635
|
-
v0 = Libbcmath.new_sub_num(n, 0, v.n_value, vlen - n)
|
|
644
|
+
v1 = Libbcmath.new_sub_num(vlen - n, 0, v.n_value)
|
|
645
|
+
v0 = Libbcmath.new_sub_num(n, 0, v.n_value, vlen - n)
|
|
636
646
|
}
|
|
637
|
-
Libbcmath._bc_rm_leading_zeros(u1)
|
|
638
|
-
Libbcmath._bc_rm_leading_zeros(u0)
|
|
647
|
+
Libbcmath._bc_rm_leading_zeros(u1)
|
|
648
|
+
Libbcmath._bc_rm_leading_zeros(u0)
|
|
639
649
|
// var u0len = u0.n_len
|
|
640
|
-
Libbcmath._bc_rm_leading_zeros(v1)
|
|
641
|
-
Libbcmath._bc_rm_leading_zeros(v0)
|
|
650
|
+
Libbcmath._bc_rm_leading_zeros(v1)
|
|
651
|
+
Libbcmath._bc_rm_leading_zeros(v0)
|
|
642
652
|
// var v0len = v0.n_len
|
|
643
653
|
|
|
644
|
-
m1zero = Libbcmath.bc_is_zero(u1) || Libbcmath.bc_is_zero(v1)
|
|
654
|
+
m1zero = Libbcmath.bc_is_zero(u1) || Libbcmath.bc_is_zero(v1)
|
|
645
655
|
|
|
646
656
|
// Calculate sub results ...
|
|
647
|
-
d1 = Libbcmath.bc_init_num()
|
|
648
|
-
d2 = Libbcmath.bc_init_num()
|
|
649
|
-
d1 = Libbcmath.bc_sub(u1, u0, 0)
|
|
650
|
-
d1len = d1.n_len
|
|
657
|
+
d1 = Libbcmath.bc_init_num() // needed?
|
|
658
|
+
d2 = Libbcmath.bc_init_num() // needed?
|
|
659
|
+
d1 = Libbcmath.bc_sub(u1, u0, 0)
|
|
660
|
+
d1len = d1.n_len
|
|
651
661
|
|
|
652
|
-
d2 = Libbcmath.bc_sub(v0, v1, 0)
|
|
653
|
-
d2len = d2.n_len
|
|
662
|
+
d2 = Libbcmath.bc_sub(v0, v1, 0)
|
|
663
|
+
d2len = d2.n_len
|
|
654
664
|
|
|
655
665
|
// Do recursive multiplies and shifted adds.
|
|
656
666
|
if (m1zero) {
|
|
657
|
-
m1 = Libbcmath.bc_init_num()
|
|
667
|
+
m1 = Libbcmath.bc_init_num() // bc_copy_num (BCG(_zero_));
|
|
658
668
|
} else {
|
|
659
669
|
// m1 = Libbcmath.bc_init_num(); //allow pass-by-ref
|
|
660
|
-
m1 = Libbcmath._bc_rec_mul(u1, u1.n_len, v1, v1.n_len, 0)
|
|
670
|
+
m1 = Libbcmath._bc_rec_mul(u1, u1.n_len, v1, v1.n_len, 0)
|
|
661
671
|
}
|
|
662
672
|
if (Libbcmath.bc_is_zero(d1) || Libbcmath.bc_is_zero(d2)) {
|
|
663
|
-
m2 = Libbcmath.bc_init_num()
|
|
673
|
+
m2 = Libbcmath.bc_init_num() // bc_copy_num (BCG(_zero_));
|
|
664
674
|
} else {
|
|
665
675
|
// m2 = Libbcmath.bc_init_num(); //allow pass-by-ref
|
|
666
|
-
m2 = Libbcmath._bc_rec_mul(d1, d1len, d2, d2len, 0)
|
|
676
|
+
m2 = Libbcmath._bc_rec_mul(d1, d1len, d2, d2len, 0)
|
|
667
677
|
}
|
|
668
678
|
|
|
669
679
|
if (Libbcmath.bc_is_zero(u0) || Libbcmath.bc_is_zero(v0)) {
|
|
670
|
-
m3 = Libbcmath.bc_init_num()
|
|
680
|
+
m3 = Libbcmath.bc_init_num() // bc_copy_num (BCG(_zero_));
|
|
671
681
|
} else {
|
|
672
682
|
// m3 = Libbcmath.bc_init_num(); //allow pass-by-ref
|
|
673
|
-
m3 = Libbcmath._bc_rec_mul(u0, u0.n_len, v0, v0.n_len, 0)
|
|
683
|
+
m3 = Libbcmath._bc_rec_mul(u0, u0.n_len, v0, v0.n_len, 0)
|
|
674
684
|
}
|
|
675
685
|
|
|
676
686
|
// Initialize product
|
|
677
|
-
prodlen = ulen + vlen + 1
|
|
678
|
-
prod = Libbcmath.bc_new_num(prodlen, 0)
|
|
687
|
+
prodlen = ulen + vlen + 1
|
|
688
|
+
prod = Libbcmath.bc_new_num(prodlen, 0)
|
|
679
689
|
|
|
680
690
|
if (!m1zero) {
|
|
681
|
-
Libbcmath._bc_shift_addsub(prod, m1, 2 * n, 0)
|
|
682
|
-
Libbcmath._bc_shift_addsub(prod, m1, n, 0)
|
|
691
|
+
Libbcmath._bc_shift_addsub(prod, m1, 2 * n, 0)
|
|
692
|
+
Libbcmath._bc_shift_addsub(prod, m1, n, 0)
|
|
683
693
|
}
|
|
684
|
-
Libbcmath._bc_shift_addsub(prod, m3, n, 0)
|
|
685
|
-
Libbcmath._bc_shift_addsub(prod, m3, 0, 0)
|
|
686
|
-
Libbcmath._bc_shift_addsub(prod, m2, n, d1.n_sign !== d2.n_sign)
|
|
694
|
+
Libbcmath._bc_shift_addsub(prod, m3, n, 0)
|
|
695
|
+
Libbcmath._bc_shift_addsub(prod, m3, 0, 0)
|
|
696
|
+
Libbcmath._bc_shift_addsub(prod, m2, n, d1.n_sign !== d2.n_sign)
|
|
687
697
|
|
|
688
|
-
return prod
|
|
698
|
+
return prod
|
|
689
699
|
// Now clean up!
|
|
690
700
|
// bc_free_num (&u1);
|
|
691
701
|
// bc_free_num (&u0);
|
|
@@ -706,17 +716,17 @@ module.exports = function _bc() {
|
|
|
706
716
|
* @param {boolean} ignoreLast
|
|
707
717
|
* @return -1, 0, 1 (see bc_compare)
|
|
708
718
|
*/
|
|
709
|
-
_bc_do_compare: function
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
719
|
+
_bc_do_compare: function (n1, n2, useSign, ignoreLast) {
|
|
720
|
+
let n1ptr
|
|
721
|
+
let n2ptr // int
|
|
722
|
+
let count // int
|
|
713
723
|
// First, compare signs.
|
|
714
724
|
if (useSign && n1.n_sign !== n2.n_sign) {
|
|
715
725
|
if (n1.n_sign === Libbcmath.PLUS) {
|
|
716
|
-
return 1
|
|
726
|
+
return 1 // Positive N1 > Negative N2
|
|
717
727
|
} else {
|
|
718
|
-
|
|
719
|
-
|
|
728
|
+
return -1 // Negative N1 < Positive N1
|
|
729
|
+
}
|
|
720
730
|
}
|
|
721
731
|
|
|
722
732
|
// Now compare the magnitude.
|
|
@@ -724,50 +734,50 @@ module.exports = function _bc() {
|
|
|
724
734
|
if (n1.n_len > n2.n_len) {
|
|
725
735
|
// Magnitude of n1 > n2.
|
|
726
736
|
if (!useSign || n1.n_sign === Libbcmath.PLUS) {
|
|
727
|
-
return 1
|
|
737
|
+
return 1
|
|
728
738
|
} else {
|
|
729
|
-
return -1
|
|
739
|
+
return -1
|
|
730
740
|
}
|
|
731
741
|
} else {
|
|
732
742
|
// Magnitude of n1 < n2.
|
|
733
743
|
if (!useSign || n1.n_sign === Libbcmath.PLUS) {
|
|
734
|
-
return -1
|
|
744
|
+
return -1
|
|
735
745
|
} else {
|
|
736
|
-
return 1
|
|
746
|
+
return 1
|
|
737
747
|
}
|
|
738
748
|
}
|
|
739
749
|
}
|
|
740
750
|
|
|
741
751
|
/* If we get here, they have the same number of integer digits.
|
|
742
|
-
|
|
743
|
-
count = n1.n_len + Math.min(n1.n_scale, n2.n_scale)
|
|
744
|
-
n1ptr = 0
|
|
745
|
-
n2ptr = 0
|
|
752
|
+
check the integer part and the equal length part of the fraction. */
|
|
753
|
+
count = n1.n_len + Math.min(n1.n_scale, n2.n_scale)
|
|
754
|
+
n1ptr = 0
|
|
755
|
+
n2ptr = 0
|
|
746
756
|
|
|
747
757
|
while (count > 0 && n1.n_value[n1ptr] === n2.n_value[n2ptr]) {
|
|
748
|
-
n1ptr
|
|
749
|
-
n2ptr
|
|
750
|
-
count
|
|
758
|
+
n1ptr++
|
|
759
|
+
n2ptr++
|
|
760
|
+
count--
|
|
751
761
|
}
|
|
752
762
|
|
|
753
763
|
if (ignoreLast && count === 1 && n1.n_scale === n2.n_scale) {
|
|
754
|
-
return 0
|
|
764
|
+
return 0
|
|
755
765
|
}
|
|
756
766
|
|
|
757
767
|
if (count !== 0) {
|
|
758
768
|
if (n1.n_value[n1ptr] > n2.n_value[n2ptr]) {
|
|
759
769
|
// Magnitude of n1 > n2.
|
|
760
770
|
if (!useSign || n1.n_sign === Libbcmath.PLUS) {
|
|
761
|
-
return 1
|
|
771
|
+
return 1
|
|
762
772
|
} else {
|
|
763
|
-
return -1
|
|
773
|
+
return -1
|
|
764
774
|
}
|
|
765
775
|
} else {
|
|
766
776
|
// Magnitude of n1 < n2.
|
|
767
777
|
if (!useSign || n1.n_sign === Libbcmath.PLUS) {
|
|
768
|
-
return -1
|
|
778
|
+
return -1
|
|
769
779
|
} else {
|
|
770
|
-
return 1
|
|
780
|
+
return 1
|
|
771
781
|
}
|
|
772
782
|
}
|
|
773
783
|
}
|
|
@@ -779,9 +789,9 @@ module.exports = function _bc() {
|
|
|
779
789
|
if (n1.n_value[n1ptr++] !== 0) {
|
|
780
790
|
// Magnitude of n1 > n2.
|
|
781
791
|
if (!useSign || n1.n_sign === Libbcmath.PLUS) {
|
|
782
|
-
return 1
|
|
792
|
+
return 1
|
|
783
793
|
} else {
|
|
784
|
-
return -1
|
|
794
|
+
return -1
|
|
785
795
|
}
|
|
786
796
|
}
|
|
787
797
|
}
|
|
@@ -790,9 +800,9 @@ module.exports = function _bc() {
|
|
|
790
800
|
if (n2.n_value[n2ptr++] !== 0) {
|
|
791
801
|
// Magnitude of n1 < n2.
|
|
792
802
|
if (!useSign || n1.n_sign === Libbcmath.PLUS) {
|
|
793
|
-
return -1
|
|
803
|
+
return -1
|
|
794
804
|
} else {
|
|
795
|
-
return 1
|
|
805
|
+
return 1
|
|
796
806
|
}
|
|
797
807
|
}
|
|
798
808
|
}
|
|
@@ -800,72 +810,72 @@ module.exports = function _bc() {
|
|
|
800
810
|
}
|
|
801
811
|
|
|
802
812
|
// They must be equal!
|
|
803
|
-
return 0
|
|
813
|
+
return 0
|
|
804
814
|
},
|
|
805
815
|
|
|
806
816
|
/* Here is the full subtract routine that takes care of negative numbers.
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
bc_sub: function
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
817
|
+
N2 is subtracted from N1 and the result placed in RESULT. SCALE_MIN
|
|
818
|
+
is the minimum scale for the result. */
|
|
819
|
+
bc_sub: function (n1, n2, scaleMin) {
|
|
820
|
+
let diff // bc_num
|
|
821
|
+
let cmpRes
|
|
822
|
+
let resScale // int
|
|
813
823
|
if (n1.n_sign !== n2.n_sign) {
|
|
814
|
-
diff = Libbcmath._bc_do_add(n1, n2, scaleMin)
|
|
815
|
-
diff.n_sign = n1.n_sign
|
|
824
|
+
diff = Libbcmath._bc_do_add(n1, n2, scaleMin)
|
|
825
|
+
diff.n_sign = n1.n_sign
|
|
816
826
|
} else {
|
|
817
827
|
// subtraction must be done.
|
|
818
828
|
// Compare magnitudes.
|
|
819
|
-
cmpRes = Libbcmath._bc_do_compare(n1, n2, false, false)
|
|
829
|
+
cmpRes = Libbcmath._bc_do_compare(n1, n2, false, false)
|
|
820
830
|
switch (cmpRes) {
|
|
821
831
|
case -1:
|
|
822
832
|
// n1 is less than n2, subtract n1 from n2.
|
|
823
|
-
diff = Libbcmath._bc_do_sub(n2, n1, scaleMin)
|
|
824
|
-
diff.n_sign = n2.n_sign === Libbcmath.PLUS ? Libbcmath.MINUS : Libbcmath.PLUS
|
|
825
|
-
break
|
|
833
|
+
diff = Libbcmath._bc_do_sub(n2, n1, scaleMin)
|
|
834
|
+
diff.n_sign = n2.n_sign === Libbcmath.PLUS ? Libbcmath.MINUS : Libbcmath.PLUS
|
|
835
|
+
break
|
|
826
836
|
case 0:
|
|
827
837
|
// They are equal! return zero!
|
|
828
|
-
resScale = Libbcmath.MAX(scaleMin, Libbcmath.MAX(n1.n_scale, n2.n_scale))
|
|
829
|
-
diff = Libbcmath.bc_new_num(1, resScale)
|
|
830
|
-
Libbcmath.memset(diff.n_value, 0, 0, resScale + 1)
|
|
831
|
-
break
|
|
838
|
+
resScale = Libbcmath.MAX(scaleMin, Libbcmath.MAX(n1.n_scale, n2.n_scale))
|
|
839
|
+
diff = Libbcmath.bc_new_num(1, resScale)
|
|
840
|
+
Libbcmath.memset(diff.n_value, 0, 0, resScale + 1)
|
|
841
|
+
break
|
|
832
842
|
case 1:
|
|
833
843
|
// n2 is less than n1, subtract n2 from n1.
|
|
834
|
-
diff = Libbcmath._bc_do_sub(n1, n2, scaleMin)
|
|
835
|
-
diff.n_sign = n1.n_sign
|
|
836
|
-
break
|
|
844
|
+
diff = Libbcmath._bc_do_sub(n1, n2, scaleMin)
|
|
845
|
+
diff.n_sign = n1.n_sign
|
|
846
|
+
break
|
|
837
847
|
}
|
|
838
848
|
}
|
|
839
849
|
|
|
840
850
|
// Clean up and return.
|
|
841
851
|
// bc_free_num (result);
|
|
842
852
|
//* result = diff;
|
|
843
|
-
return diff
|
|
853
|
+
return diff
|
|
844
854
|
},
|
|
845
855
|
|
|
846
|
-
_bc_do_add: function
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
856
|
+
_bc_do_add: function (n1, n2, scaleMin) {
|
|
857
|
+
let sum // bc_num
|
|
858
|
+
let sumScale
|
|
859
|
+
let sumDigits // int
|
|
860
|
+
let n1ptr
|
|
861
|
+
let n2ptr
|
|
862
|
+
let sumptr // int
|
|
863
|
+
let carry
|
|
864
|
+
let n1bytes
|
|
865
|
+
let n2bytes // int
|
|
866
|
+
let tmp // int
|
|
857
867
|
|
|
858
868
|
// Prepare sum.
|
|
859
|
-
sumScale = Libbcmath.MAX(n1.n_scale, n2.n_scale)
|
|
860
|
-
sumDigits = Libbcmath.MAX(n1.n_len, n2.n_len) + 1
|
|
861
|
-
sum = Libbcmath.bc_new_num(sumDigits, Libbcmath.MAX(sumScale, scaleMin))
|
|
869
|
+
sumScale = Libbcmath.MAX(n1.n_scale, n2.n_scale)
|
|
870
|
+
sumDigits = Libbcmath.MAX(n1.n_len, n2.n_len) + 1
|
|
871
|
+
sum = Libbcmath.bc_new_num(sumDigits, Libbcmath.MAX(sumScale, scaleMin))
|
|
862
872
|
|
|
863
873
|
// Start with the fraction part. Initialize the pointers.
|
|
864
|
-
n1bytes = n1.n_scale
|
|
865
|
-
n2bytes = n2.n_scale
|
|
866
|
-
n1ptr = n1.n_len + n1bytes - 1
|
|
867
|
-
n2ptr = n2.n_len + n2bytes - 1
|
|
868
|
-
sumptr = sumScale + sumDigits - 1
|
|
874
|
+
n1bytes = n1.n_scale
|
|
875
|
+
n2bytes = n2.n_scale
|
|
876
|
+
n1ptr = n1.n_len + n1bytes - 1
|
|
877
|
+
n2ptr = n2.n_len + n2bytes - 1
|
|
878
|
+
sumptr = sumScale + sumDigits - 1
|
|
869
879
|
|
|
870
880
|
// Add the fraction part. First copy the longer fraction
|
|
871
881
|
// (ie when adding 1.2345 to 1 we know .2345 is correct already) .
|
|
@@ -873,79 +883,79 @@ module.exports = function _bc() {
|
|
|
873
883
|
if (n1bytes > n2bytes) {
|
|
874
884
|
// n1 has more dp then n2
|
|
875
885
|
while (n1bytes > n2bytes) {
|
|
876
|
-
sum.n_value[sumptr--] = n1.n_value[n1ptr--]
|
|
886
|
+
sum.n_value[sumptr--] = n1.n_value[n1ptr--]
|
|
877
887
|
// *sumptr-- = *n1ptr--;
|
|
878
|
-
n1bytes
|
|
888
|
+
n1bytes--
|
|
879
889
|
}
|
|
880
890
|
} else {
|
|
881
891
|
// n2 has more dp then n1
|
|
882
892
|
while (n2bytes > n1bytes) {
|
|
883
|
-
sum.n_value[sumptr--] = n2.n_value[n2ptr--]
|
|
893
|
+
sum.n_value[sumptr--] = n2.n_value[n2ptr--]
|
|
884
894
|
// *sumptr-- = *n2ptr--;
|
|
885
|
-
n2bytes
|
|
895
|
+
n2bytes--
|
|
886
896
|
}
|
|
887
897
|
}
|
|
888
898
|
}
|
|
889
899
|
|
|
890
900
|
// Now add the remaining fraction part and equal size integer parts.
|
|
891
|
-
n1bytes += n1.n_len
|
|
892
|
-
n2bytes += n2.n_len
|
|
893
|
-
carry = 0
|
|
901
|
+
n1bytes += n1.n_len
|
|
902
|
+
n2bytes += n2.n_len
|
|
903
|
+
carry = 0
|
|
894
904
|
while (n1bytes > 0 && n2bytes > 0) {
|
|
895
905
|
// add the two numbers together
|
|
896
|
-
tmp = n1.n_value[n1ptr--] + n2.n_value[n2ptr--] + carry
|
|
906
|
+
tmp = n1.n_value[n1ptr--] + n2.n_value[n2ptr--] + carry
|
|
897
907
|
// *sumptr = *n1ptr-- + *n2ptr-- + carry;
|
|
898
908
|
// check if they are >= 10 (impossible to be more then 18)
|
|
899
909
|
if (tmp >= Libbcmath.BASE) {
|
|
900
|
-
carry = 1
|
|
901
|
-
tmp -= Libbcmath.BASE
|
|
910
|
+
carry = 1
|
|
911
|
+
tmp -= Libbcmath.BASE // yep, subtract 10, add a carry
|
|
902
912
|
} else {
|
|
903
|
-
carry = 0
|
|
913
|
+
carry = 0
|
|
904
914
|
}
|
|
905
|
-
sum.n_value[sumptr] = tmp
|
|
906
|
-
sumptr
|
|
907
|
-
n1bytes
|
|
908
|
-
n2bytes
|
|
915
|
+
sum.n_value[sumptr] = tmp
|
|
916
|
+
sumptr--
|
|
917
|
+
n1bytes--
|
|
918
|
+
n2bytes--
|
|
909
919
|
}
|
|
910
920
|
|
|
911
921
|
// Now add carry the [rest of the] longer integer part.
|
|
912
922
|
if (n1bytes === 0) {
|
|
913
923
|
// n2 is a bigger number then n1
|
|
914
924
|
while (n2bytes-- > 0) {
|
|
915
|
-
tmp = n2.n_value[n2ptr--] + carry
|
|
925
|
+
tmp = n2.n_value[n2ptr--] + carry
|
|
916
926
|
// *sumptr = *n2ptr-- + carry;
|
|
917
927
|
if (tmp >= Libbcmath.BASE) {
|
|
918
|
-
carry = 1
|
|
919
|
-
tmp -= Libbcmath.BASE
|
|
928
|
+
carry = 1
|
|
929
|
+
tmp -= Libbcmath.BASE
|
|
920
930
|
} else {
|
|
921
|
-
carry = 0
|
|
931
|
+
carry = 0
|
|
922
932
|
}
|
|
923
|
-
sum.n_value[sumptr--] = tmp
|
|
933
|
+
sum.n_value[sumptr--] = tmp
|
|
924
934
|
}
|
|
925
935
|
} else {
|
|
926
936
|
// n1 is bigger then n2..
|
|
927
937
|
while (n1bytes-- > 0) {
|
|
928
|
-
tmp = n1.n_value[n1ptr--] + carry
|
|
938
|
+
tmp = n1.n_value[n1ptr--] + carry
|
|
929
939
|
// *sumptr = *n1ptr-- + carry;
|
|
930
940
|
if (tmp >= Libbcmath.BASE) {
|
|
931
|
-
carry = 1
|
|
932
|
-
tmp -= Libbcmath.BASE
|
|
941
|
+
carry = 1
|
|
942
|
+
tmp -= Libbcmath.BASE
|
|
933
943
|
} else {
|
|
934
|
-
carry = 0
|
|
944
|
+
carry = 0
|
|
935
945
|
}
|
|
936
|
-
sum.n_value[sumptr--] = tmp
|
|
946
|
+
sum.n_value[sumptr--] = tmp
|
|
937
947
|
}
|
|
938
948
|
}
|
|
939
949
|
|
|
940
950
|
// Set final carry.
|
|
941
951
|
if (carry === 1) {
|
|
942
|
-
sum.n_value[sumptr] += 1
|
|
952
|
+
sum.n_value[sumptr] += 1
|
|
943
953
|
// *sumptr += 1;
|
|
944
954
|
}
|
|
945
955
|
|
|
946
956
|
// Adjust sum and return.
|
|
947
|
-
Libbcmath._bc_rm_leading_zeros(sum)
|
|
948
|
-
return sum
|
|
957
|
+
Libbcmath._bc_rm_leading_zeros(sum)
|
|
958
|
+
return sum
|
|
949
959
|
},
|
|
950
960
|
|
|
951
961
|
/**
|
|
@@ -967,24 +977,24 @@ module.exports = function _bc() {
|
|
|
967
977
|
* @param {int} scaleMin
|
|
968
978
|
* @return bc_num
|
|
969
979
|
*/
|
|
970
|
-
_bc_do_sub: function
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
980
|
+
_bc_do_sub: function (n1, n2, scaleMin) {
|
|
981
|
+
let diff // bc_num
|
|
982
|
+
let diffScale
|
|
983
|
+
let diffLen // int
|
|
984
|
+
let minScale
|
|
985
|
+
let minLen // int
|
|
986
|
+
let n1ptr
|
|
987
|
+
let n2ptr
|
|
988
|
+
let diffptr // int
|
|
989
|
+
let borrow
|
|
990
|
+
let count
|
|
991
|
+
let val // int
|
|
982
992
|
// Allocate temporary storage.
|
|
983
|
-
diffLen = Libbcmath.MAX(n1.n_len, n2.n_len)
|
|
984
|
-
diffScale = Libbcmath.MAX(n1.n_scale, n2.n_scale)
|
|
985
|
-
minLen = Libbcmath.MIN(n1.n_len, n2.n_len)
|
|
986
|
-
minScale = Libbcmath.MIN(n1.n_scale, n2.n_scale)
|
|
987
|
-
diff = Libbcmath.bc_new_num(diffLen, Libbcmath.MAX(diffScale, scaleMin))
|
|
993
|
+
diffLen = Libbcmath.MAX(n1.n_len, n2.n_len)
|
|
994
|
+
diffScale = Libbcmath.MAX(n1.n_scale, n2.n_scale)
|
|
995
|
+
minLen = Libbcmath.MIN(n1.n_len, n2.n_len)
|
|
996
|
+
minScale = Libbcmath.MIN(n1.n_scale, n2.n_scale)
|
|
997
|
+
diff = Libbcmath.bc_new_num(diffLen, Libbcmath.MAX(diffScale, scaleMin))
|
|
988
998
|
|
|
989
999
|
/* Not needed?
|
|
990
1000
|
// Zero extra digits made by scaleMin.
|
|
@@ -997,68 +1007,68 @@ module.exports = function _bc() {
|
|
|
997
1007
|
*/
|
|
998
1008
|
|
|
999
1009
|
// Initialize the subtract.
|
|
1000
|
-
n1ptr = n1.n_len + n1.n_scale - 1
|
|
1001
|
-
n2ptr = n2.n_len + n2.n_scale - 1
|
|
1002
|
-
diffptr = diffLen + diffScale - 1
|
|
1010
|
+
n1ptr = n1.n_len + n1.n_scale - 1
|
|
1011
|
+
n2ptr = n2.n_len + n2.n_scale - 1
|
|
1012
|
+
diffptr = diffLen + diffScale - 1
|
|
1003
1013
|
|
|
1004
1014
|
// Subtract the numbers.
|
|
1005
|
-
borrow = 0
|
|
1015
|
+
borrow = 0
|
|
1006
1016
|
|
|
1007
1017
|
// Take care of the longer scaled number.
|
|
1008
1018
|
if (n1.n_scale !== minScale) {
|
|
1009
1019
|
// n1 has the longer scale
|
|
1010
1020
|
for (count = n1.n_scale - minScale; count > 0; count--) {
|
|
1011
|
-
diff.n_value[diffptr--] = n1.n_value[n1ptr--]
|
|
1021
|
+
diff.n_value[diffptr--] = n1.n_value[n1ptr--]
|
|
1012
1022
|
// *diffptr-- = *n1ptr--;
|
|
1013
1023
|
}
|
|
1014
1024
|
} else {
|
|
1015
1025
|
// n2 has the longer scale
|
|
1016
1026
|
for (count = n2.n_scale - minScale; count > 0; count--) {
|
|
1017
|
-
val = 0 - n2.n_value[n2ptr--] - borrow
|
|
1027
|
+
val = 0 - n2.n_value[n2ptr--] - borrow
|
|
1018
1028
|
// val = - *n2ptr-- - borrow;
|
|
1019
1029
|
if (val < 0) {
|
|
1020
|
-
val += Libbcmath.BASE
|
|
1021
|
-
borrow = 1
|
|
1030
|
+
val += Libbcmath.BASE
|
|
1031
|
+
borrow = 1
|
|
1022
1032
|
} else {
|
|
1023
|
-
borrow = 0
|
|
1033
|
+
borrow = 0
|
|
1024
1034
|
}
|
|
1025
|
-
diff.n_value[diffptr--] = val
|
|
1035
|
+
diff.n_value[diffptr--] = val
|
|
1026
1036
|
//* diffptr-- = val;
|
|
1027
1037
|
}
|
|
1028
1038
|
}
|
|
1029
1039
|
|
|
1030
1040
|
// Now do the equal length scale and integer parts.
|
|
1031
1041
|
for (count = 0; count < minLen + minScale; count++) {
|
|
1032
|
-
val = n1.n_value[n1ptr--] - n2.n_value[n2ptr--] - borrow
|
|
1042
|
+
val = n1.n_value[n1ptr--] - n2.n_value[n2ptr--] - borrow
|
|
1033
1043
|
// val = *n1ptr-- - *n2ptr-- - borrow;
|
|
1034
1044
|
if (val < 0) {
|
|
1035
|
-
val += Libbcmath.BASE
|
|
1036
|
-
borrow = 1
|
|
1045
|
+
val += Libbcmath.BASE
|
|
1046
|
+
borrow = 1
|
|
1037
1047
|
} else {
|
|
1038
|
-
borrow = 0
|
|
1048
|
+
borrow = 0
|
|
1039
1049
|
}
|
|
1040
|
-
diff.n_value[diffptr--] = val
|
|
1050
|
+
diff.n_value[diffptr--] = val
|
|
1041
1051
|
//* diffptr-- = val;
|
|
1042
1052
|
}
|
|
1043
1053
|
|
|
1044
1054
|
// If n1 has more digits then n2, we now do that subtract.
|
|
1045
1055
|
if (diffLen !== minLen) {
|
|
1046
1056
|
for (count = diffLen - minLen; count > 0; count--) {
|
|
1047
|
-
val = n1.n_value[n1ptr--] - borrow
|
|
1057
|
+
val = n1.n_value[n1ptr--] - borrow
|
|
1048
1058
|
// val = *n1ptr-- - borrow;
|
|
1049
1059
|
if (val < 0) {
|
|
1050
|
-
val += Libbcmath.BASE
|
|
1051
|
-
borrow = 1
|
|
1060
|
+
val += Libbcmath.BASE
|
|
1061
|
+
borrow = 1
|
|
1052
1062
|
} else {
|
|
1053
|
-
borrow = 0
|
|
1063
|
+
borrow = 0
|
|
1054
1064
|
}
|
|
1055
|
-
diff.n_value[diffptr--] = val
|
|
1065
|
+
diff.n_value[diffptr--] = val
|
|
1056
1066
|
}
|
|
1057
1067
|
}
|
|
1058
1068
|
|
|
1059
1069
|
// Clean up and return.
|
|
1060
|
-
Libbcmath._bc_rm_leading_zeros(diff)
|
|
1061
|
-
return diff
|
|
1070
|
+
Libbcmath._bc_rm_leading_zeros(diff)
|
|
1071
|
+
return diff
|
|
1062
1072
|
},
|
|
1063
1073
|
|
|
1064
1074
|
/**
|
|
@@ -1067,162 +1077,162 @@ module.exports = function _bc() {
|
|
|
1067
1077
|
* @param {int} scale
|
|
1068
1078
|
* @return bc_num
|
|
1069
1079
|
*/
|
|
1070
|
-
bc_new_num: function
|
|
1071
|
-
|
|
1072
|
-
temp = new Libbcmath.bc_num()
|
|
1073
|
-
temp.n_sign = Libbcmath.PLUS
|
|
1074
|
-
temp.n_len = length
|
|
1075
|
-
temp.n_scale = scale
|
|
1076
|
-
temp.n_value = Libbcmath.safe_emalloc(1, length + scale, 0)
|
|
1077
|
-
Libbcmath.memset(temp.n_value, 0, 0, length + scale)
|
|
1078
|
-
return temp
|
|
1080
|
+
bc_new_num: function (length, scale) {
|
|
1081
|
+
let temp // bc_num
|
|
1082
|
+
temp = new Libbcmath.bc_num()
|
|
1083
|
+
temp.n_sign = Libbcmath.PLUS
|
|
1084
|
+
temp.n_len = length
|
|
1085
|
+
temp.n_scale = scale
|
|
1086
|
+
temp.n_value = Libbcmath.safe_emalloc(1, length + scale, 0)
|
|
1087
|
+
Libbcmath.memset(temp.n_value, 0, 0, length + scale)
|
|
1088
|
+
return temp
|
|
1079
1089
|
},
|
|
1080
1090
|
|
|
1081
|
-
safe_emalloc: function
|
|
1082
|
-
return Array(size * len + extra)
|
|
1091
|
+
safe_emalloc: function (size, len, extra) {
|
|
1092
|
+
return new Array(size * len + extra)
|
|
1083
1093
|
},
|
|
1084
1094
|
|
|
1085
1095
|
/**
|
|
1086
1096
|
* Create a new number
|
|
1087
1097
|
*/
|
|
1088
|
-
bc_init_num: function
|
|
1089
|
-
return new Libbcmath.bc_new_num(1, 0)
|
|
1098
|
+
bc_init_num: function () {
|
|
1099
|
+
return new Libbcmath.bc_new_num(1, 0)
|
|
1090
1100
|
},
|
|
1091
1101
|
|
|
1092
|
-
_bc_rm_leading_zeros: function
|
|
1102
|
+
_bc_rm_leading_zeros: function (num) {
|
|
1093
1103
|
// We can move n_value to point to the first non zero digit!
|
|
1094
1104
|
while (num.n_value[0] === 0 && num.n_len > 1) {
|
|
1095
|
-
num.n_value.shift()
|
|
1096
|
-
num.n_len
|
|
1105
|
+
num.n_value.shift()
|
|
1106
|
+
num.n_len--
|
|
1097
1107
|
}
|
|
1098
1108
|
},
|
|
1099
1109
|
|
|
1100
1110
|
/**
|
|
1101
1111
|
* Convert to bc_num detecting scale
|
|
1102
1112
|
*/
|
|
1103
|
-
php_str2num: function
|
|
1104
|
-
|
|
1105
|
-
p = str.indexOf('.')
|
|
1113
|
+
php_str2num: function (str) {
|
|
1114
|
+
let p
|
|
1115
|
+
p = str.indexOf('.')
|
|
1106
1116
|
if (p === -1) {
|
|
1107
|
-
return Libbcmath.bc_str2num(str, 0)
|
|
1117
|
+
return Libbcmath.bc_str2num(str, 0)
|
|
1108
1118
|
} else {
|
|
1109
|
-
return Libbcmath.bc_str2num(str, str.length - p)
|
|
1119
|
+
return Libbcmath.bc_str2num(str, str.length - p)
|
|
1110
1120
|
}
|
|
1111
1121
|
},
|
|
1112
1122
|
|
|
1113
|
-
CH_VAL: function
|
|
1114
|
-
return c - '0'
|
|
1123
|
+
CH_VAL: function (c) {
|
|
1124
|
+
return c - '0' // ??
|
|
1115
1125
|
},
|
|
1116
1126
|
|
|
1117
|
-
BCD_CHAR: function
|
|
1118
|
-
return d + '0'
|
|
1127
|
+
BCD_CHAR: function (d) {
|
|
1128
|
+
return d + '0' // ??
|
|
1119
1129
|
},
|
|
1120
1130
|
|
|
1121
|
-
isdigit: function
|
|
1122
|
-
return isNaN(parseInt(c, 10))
|
|
1131
|
+
isdigit: function (c) {
|
|
1132
|
+
return isNaN(parseInt(c, 10))
|
|
1123
1133
|
},
|
|
1124
1134
|
|
|
1125
|
-
bc_str2num: function
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1135
|
+
bc_str2num: function (strIn, scale) {
|
|
1136
|
+
let str
|
|
1137
|
+
let num
|
|
1138
|
+
let ptr
|
|
1139
|
+
let digits
|
|
1140
|
+
let strscale
|
|
1141
|
+
let zeroInt
|
|
1142
|
+
let nptr
|
|
1133
1143
|
// remove any non-expected characters
|
|
1134
1144
|
// Check for valid number and count digits.
|
|
1135
1145
|
|
|
1136
|
-
str = strIn.split('')
|
|
1137
|
-
ptr = 0
|
|
1138
|
-
digits = 0
|
|
1139
|
-
strscale = 0
|
|
1140
|
-
zeroInt = false
|
|
1146
|
+
str = strIn.split('') // convert to array
|
|
1147
|
+
ptr = 0 // str
|
|
1148
|
+
digits = 0
|
|
1149
|
+
strscale = 0
|
|
1150
|
+
zeroInt = false
|
|
1141
1151
|
if (str[ptr] === '+' || str[ptr] === '-') {
|
|
1142
|
-
ptr
|
|
1152
|
+
ptr++ // Sign
|
|
1143
1153
|
}
|
|
1144
1154
|
while (str[ptr] === '0') {
|
|
1145
|
-
ptr
|
|
1155
|
+
ptr++ // Skip leading zeros.
|
|
1146
1156
|
}
|
|
1147
1157
|
// while (Libbcmath.isdigit(str[ptr])) {
|
|
1148
1158
|
while (str[ptr] % 1 === 0) {
|
|
1149
1159
|
// Libbcmath.isdigit(str[ptr])) {
|
|
1150
|
-
ptr
|
|
1151
|
-
digits
|
|
1160
|
+
ptr++
|
|
1161
|
+
digits++ // digits
|
|
1152
1162
|
}
|
|
1153
1163
|
|
|
1154
1164
|
if (str[ptr] === '.') {
|
|
1155
|
-
ptr
|
|
1165
|
+
ptr++ // decimal point
|
|
1156
1166
|
}
|
|
1157
1167
|
// while (Libbcmath.isdigit(str[ptr])) {
|
|
1158
1168
|
while (str[ptr] % 1 === 0) {
|
|
1159
1169
|
// Libbcmath.isdigit(str[ptr])) {
|
|
1160
|
-
ptr
|
|
1161
|
-
strscale
|
|
1170
|
+
ptr++
|
|
1171
|
+
strscale++ // digits
|
|
1162
1172
|
}
|
|
1163
1173
|
|
|
1164
1174
|
if (str[ptr] || digits + strscale === 0) {
|
|
1165
1175
|
// invalid number, return 0
|
|
1166
|
-
return Libbcmath.bc_init_num()
|
|
1176
|
+
return Libbcmath.bc_init_num()
|
|
1167
1177
|
//* num = bc_copy_num (BCG(_zero_));
|
|
1168
1178
|
}
|
|
1169
1179
|
|
|
1170
1180
|
// Adjust numbers and allocate storage and initialize fields.
|
|
1171
|
-
strscale = Libbcmath.MIN(strscale, scale)
|
|
1181
|
+
strscale = Libbcmath.MIN(strscale, scale)
|
|
1172
1182
|
if (digits === 0) {
|
|
1173
|
-
zeroInt = true
|
|
1174
|
-
digits = 1
|
|
1183
|
+
zeroInt = true
|
|
1184
|
+
digits = 1
|
|
1175
1185
|
}
|
|
1176
1186
|
|
|
1177
|
-
num = Libbcmath.bc_new_num(digits, strscale)
|
|
1187
|
+
num = Libbcmath.bc_new_num(digits, strscale)
|
|
1178
1188
|
|
|
1179
1189
|
// Build the whole number.
|
|
1180
|
-
ptr = 0
|
|
1190
|
+
ptr = 0 // str
|
|
1181
1191
|
if (str[ptr] === '-') {
|
|
1182
|
-
num.n_sign = Libbcmath.MINUS
|
|
1192
|
+
num.n_sign = Libbcmath.MINUS
|
|
1183
1193
|
// (*num)->n_sign = MINUS;
|
|
1184
|
-
ptr
|
|
1194
|
+
ptr++
|
|
1185
1195
|
} else {
|
|
1186
|
-
num.n_sign = Libbcmath.PLUS
|
|
1196
|
+
num.n_sign = Libbcmath.PLUS
|
|
1187
1197
|
// (*num)->n_sign = PLUS;
|
|
1188
1198
|
if (str[ptr] === '+') {
|
|
1189
|
-
ptr
|
|
1199
|
+
ptr++
|
|
1190
1200
|
}
|
|
1191
1201
|
}
|
|
1192
1202
|
while (str[ptr] === '0') {
|
|
1193
|
-
ptr
|
|
1203
|
+
ptr++ // Skip leading zeros.
|
|
1194
1204
|
}
|
|
1195
1205
|
|
|
1196
|
-
nptr = 0
|
|
1206
|
+
nptr = 0 // (*num)->n_value;
|
|
1197
1207
|
if (zeroInt) {
|
|
1198
|
-
num.n_value[nptr++] = 0
|
|
1199
|
-
digits = 0
|
|
1208
|
+
num.n_value[nptr++] = 0
|
|
1209
|
+
digits = 0
|
|
1200
1210
|
}
|
|
1201
1211
|
for (; digits > 0; digits--) {
|
|
1202
|
-
num.n_value[nptr++] = Libbcmath.CH_VAL(str[ptr++])
|
|
1212
|
+
num.n_value[nptr++] = Libbcmath.CH_VAL(str[ptr++])
|
|
1203
1213
|
//* nptr++ = CH_VAL(*ptr++);
|
|
1204
1214
|
}
|
|
1205
1215
|
|
|
1206
1216
|
// Build the fractional part.
|
|
1207
1217
|
if (strscale > 0) {
|
|
1208
|
-
ptr
|
|
1218
|
+
ptr++ // skip the decimal point!
|
|
1209
1219
|
for (; strscale > 0; strscale--) {
|
|
1210
|
-
num.n_value[nptr++] = Libbcmath.CH_VAL(str[ptr++])
|
|
1220
|
+
num.n_value[nptr++] = Libbcmath.CH_VAL(str[ptr++])
|
|
1211
1221
|
}
|
|
1212
1222
|
}
|
|
1213
1223
|
|
|
1214
|
-
return num
|
|
1224
|
+
return num
|
|
1215
1225
|
},
|
|
1216
1226
|
|
|
1217
|
-
cint: function
|
|
1227
|
+
cint: function (v) {
|
|
1218
1228
|
if (typeof v === 'undefined') {
|
|
1219
|
-
v = 0
|
|
1229
|
+
v = 0
|
|
1220
1230
|
}
|
|
1221
|
-
|
|
1231
|
+
let x = parseInt(v, 10)
|
|
1222
1232
|
if (isNaN(x)) {
|
|
1223
|
-
x = 0
|
|
1233
|
+
x = 0
|
|
1224
1234
|
}
|
|
1225
|
-
return x
|
|
1235
|
+
return x
|
|
1226
1236
|
},
|
|
1227
1237
|
|
|
1228
1238
|
/**
|
|
@@ -1230,8 +1240,8 @@ module.exports = function _bc() {
|
|
|
1230
1240
|
* @param {int} a
|
|
1231
1241
|
* @param {int} b
|
|
1232
1242
|
*/
|
|
1233
|
-
MIN: function
|
|
1234
|
-
return a > b ? b : a
|
|
1243
|
+
MIN: function (a, b) {
|
|
1244
|
+
return a > b ? b : a
|
|
1235
1245
|
},
|
|
1236
1246
|
|
|
1237
1247
|
/**
|
|
@@ -1239,16 +1249,16 @@ module.exports = function _bc() {
|
|
|
1239
1249
|
* @param {int} a
|
|
1240
1250
|
* @param {int} b
|
|
1241
1251
|
*/
|
|
1242
|
-
MAX: function
|
|
1243
|
-
return a > b ? a : b
|
|
1252
|
+
MAX: function (a, b) {
|
|
1253
|
+
return a > b ? a : b
|
|
1244
1254
|
},
|
|
1245
1255
|
|
|
1246
1256
|
/**
|
|
1247
1257
|
* Basic odd function
|
|
1248
1258
|
* @param {int} a
|
|
1249
1259
|
*/
|
|
1250
|
-
ODD: function
|
|
1251
|
-
return a & 1
|
|
1260
|
+
ODD: function (a) {
|
|
1261
|
+
return a & 1
|
|
1252
1262
|
},
|
|
1253
1263
|
|
|
1254
1264
|
/**
|
|
@@ -1258,10 +1268,10 @@ module.exports = function _bc() {
|
|
|
1258
1268
|
* @param {string} chr char to fill
|
|
1259
1269
|
* @param {int} len length to fill
|
|
1260
1270
|
*/
|
|
1261
|
-
memset: function
|
|
1262
|
-
|
|
1271
|
+
memset: function (r, ptr, chr, len) {
|
|
1272
|
+
let i
|
|
1263
1273
|
for (i = 0; i < len; i++) {
|
|
1264
|
-
r[ptr + i] = chr
|
|
1274
|
+
r[ptr + i] = chr
|
|
1265
1275
|
}
|
|
1266
1276
|
},
|
|
1267
1277
|
|
|
@@ -1271,12 +1281,12 @@ module.exports = function _bc() {
|
|
|
1271
1281
|
* param so you could do memcpy(dest+1, src, len) as memcpy(dest, 1, src, len)
|
|
1272
1282
|
* Also only works on arrays
|
|
1273
1283
|
*/
|
|
1274
|
-
memcpy: function
|
|
1275
|
-
|
|
1284
|
+
memcpy: function (dest, ptr, src, srcptr, len) {
|
|
1285
|
+
let i
|
|
1276
1286
|
for (i = 0; i < len; i++) {
|
|
1277
|
-
dest[ptr + i] = src[srcptr + i]
|
|
1287
|
+
dest[ptr + i] = src[srcptr + i]
|
|
1278
1288
|
}
|
|
1279
|
-
return true
|
|
1289
|
+
return true
|
|
1280
1290
|
},
|
|
1281
1291
|
|
|
1282
1292
|
/**
|
|
@@ -1284,30 +1294,29 @@ module.exports = function _bc() {
|
|
|
1284
1294
|
* @param {bc_num} num number to check
|
|
1285
1295
|
* @return boolean true when zero, false when not zero.
|
|
1286
1296
|
*/
|
|
1287
|
-
bc_is_zero: function
|
|
1288
|
-
|
|
1289
|
-
|
|
1297
|
+
bc_is_zero: function (num) {
|
|
1298
|
+
let count // int
|
|
1299
|
+
let nptr // int
|
|
1290
1300
|
// Quick check.
|
|
1291
1301
|
// if (num === BCG(_zero_)) return TRUE;
|
|
1292
1302
|
// Initialize
|
|
1293
|
-
count = num.n_len + num.n_scale
|
|
1294
|
-
nptr = 0
|
|
1303
|
+
count = num.n_len + num.n_scale
|
|
1304
|
+
nptr = 0 // num->n_value;
|
|
1295
1305
|
// The check
|
|
1296
1306
|
while (count > 0 && num.n_value[nptr++] === 0) {
|
|
1297
|
-
count
|
|
1307
|
+
count--
|
|
1298
1308
|
}
|
|
1299
1309
|
|
|
1300
1310
|
if (count !== 0) {
|
|
1301
|
-
return false
|
|
1311
|
+
return false
|
|
1302
1312
|
} else {
|
|
1303
|
-
return true
|
|
1313
|
+
return true
|
|
1304
1314
|
}
|
|
1305
1315
|
},
|
|
1306
1316
|
|
|
1307
|
-
bc_out_of_memory: function
|
|
1308
|
-
throw new Error('(BC) Out of memory')
|
|
1309
|
-
}
|
|
1310
|
-
}
|
|
1311
|
-
return Libbcmath
|
|
1312
|
-
}
|
|
1313
|
-
//# sourceMappingURL=_bc.js.map
|
|
1317
|
+
bc_out_of_memory: function () {
|
|
1318
|
+
throw new Error('(BC) Out of memory')
|
|
1319
|
+
},
|
|
1320
|
+
}
|
|
1321
|
+
return Libbcmath
|
|
1322
|
+
}
|