Skip to content

Math module#2334

Merged
andrei-marinica merged 7 commits intorc/v0.66from
math-wrapper
Apr 1, 2026
Merged

Math module#2334
andrei-marinica merged 7 commits intorc/v0.66from
math-wrapper

Conversation

@andrei-marinica
Copy link
Copy Markdown
Contributor

@andrei-marinica andrei-marinica commented Mar 31, 2026

Pull request overview

Introduces a new math module in multiversx_sc that exposes linear interpolation and weighted-average helpers, and relocates internal logarithm polynomial utilities under the new module while adding corresponding unit + scenario coverage.

Changes:

  • Added math::linear_interpolation, math::weighted_average, and math::weighted_average_round_up APIs.
  • Moved the internal logarithm_i64 implementation behind math::internal_logarithm_i64 and updated BigUint / ManagedDecimal call sites.
  • Added base/scenario tests and a feature-test contract + scenario to exercise the new math APIs.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 31, 2026

Contract comparison - from 3984924 to 6768878

Path                                                                                             size                  has-allocator                     has-format
large-storage.wasm 1656 false None
send-tx-repeat.wasm 1292 false None
queue-repeat.wasm 5540 false None
linked-list-repeat.wasm 6842 false without message
map-repeat.wasm 7367 false without message
set-repeat.wasm 6515 false None
vec-repeat.wasm 4876 false None
single-value-repeat.wasm 4257 false None
str-repeat-mb-builder-cached.wasm 1109 false without message
str-repeat.wasm 2733 false without message
str-repeat-mb-builder-basic.wasm 757 false None
multiversx-wegld-swap-sc.wasm 4492 false None
multiversx-price-aggregator-sc.wasm 17910 false without message
crypto-zombies.wasm 9255 false without message
empty.wasm 244 false None
digital-cash.wasm 9845 false None
token-release.wasm 6977 false without message
bonding-curve-contract.wasm 14132 false None
crowdfunding.wasm 3557 false None
crypto-bubbles.wasm 2541 false None
nft-minter.wasm 9725 false without message
proxy-pause.wasm 4148 false None
nft-storage-prepay.wasm 2606 false None
multisig.wasm 13442 false without message
multisig-full.wasm 15130 false without message
multisig-view.wasm 5590 false None
adder.wasm 699 false None
esdt-transfer-with-fee.wasm 7502 false without message
nft-subscription.wasm 8840 false without message
kitty-genetic-alg.wasm 3494 false without message
kitty-ownership.wasm 12965 false without message
kitty-auction.wasm 9411 false without message
fractional-nfts.wasm 8306 false without message
order-book-factory.wasm 3401 false None
order-book-pair.wasm 14229 false None
ping-pong-egld.wasm 6397 false None
seed-nft-minter.wasm 14443 false without message
rewards-distribution.wasm 9605 false without message
factorial.wasm 579 false None
check-pause.wasm 1260 false None
lottery-esdt.wasm 10578 false without message
erc20.wasm 1870 false None
erc1155.wasm 12023 false without message
crowdfunding-erc20.wasm 4910 false without message
erc1155-marketplace.wasm 10602 false without message
erc721.wasm 2232 false None
erc1155-user-mock.wasm 1229 false None
lottery-erc20.wasm 12893 false without message
use-module.wasm 32741 false without message
use-module-view.wasm 736 false None
std-contract.wasm 3469 true without message
abi-tester.wasm 8607 true without message
abi-tester-ev.wasm 760 false None
rust-testing-framework-tester.wasm 8608 false None
rust-snippets-generator-test.wasm 4710 false None
exchange-features.wasm 1514 false None
formatted-message-features.wasm 3600 false without message
big-float-features.wasm 6373 false without message
multi-contract-example-feature.wasm 680 false None
multi-contract-features.wasm 681 false None
multi-contract-alt-impl.wasm 353 false None
multi-contract-features-view.wasm 1113 false None
esdt-system-sc-mock.wasm 4623 false None
child.wasm 3982 false without message
parent.wasm 1979 false None
vault-upgrade.wasm 708 false None
vault.wasm 9035 false None
mesh-node.wasm 16145 false without message
recursive-caller.wasm 5163 false without message
transfer-role-features.wasm 8667 false without message
forwarder-blind.wasm 14242 false without message
forwarder-raw-init-sync-call.wasm 2938 false None
forwarder-raw-init-async-call.wasm 2357 false None
forwarder-raw.wasm 13193 false None
forwarder-legacy.wasm 33668 false without message
first-contract.wasm 3433 false None
second-contract.wasm 1158 false None
proxy-test-second.wasm 2329 false without message
forwarder.wasm 49178 false without message
local-esdt-and-nft.wasm 12568 false without message
proxy-test-first.wasm 5719 false without message
builtin-func-features.wasm 3820 false None
scenario-tester.wasm 1374 false None
forbidden-opcodes.wasm 842 false None
alloc-mem-fail.wasm 17819 true without message
alloc-features.wasm 23267 false without message
alloc-mem-leaking.wasm 23424 false without message
payable-features.wasm 5872 false None
basic-features-small-int-bug.wasm 824 false None
basic-features-storage-bytes.wasm 541 false None
basic-features.wasm 87206 ➡️ 87712 🔴 (+506) false without message
panic-message-features.wasm 13036 false with message
panic-message-std.wasm 16074 false with message

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Introduces a new math module in multiversx_sc that exposes linear interpolation and weighted-average helpers, and relocates internal logarithm polynomial utilities under the new module while adding corresponding unit + scenario coverage.

Changes:

  • Added math::linear_interpolation, math::weighted_average, and math::weighted_average_round_up APIs.
  • Moved the internal logarithm_i64 implementation behind math::internal_logarithm_i64 and updated BigUint / ManagedDecimal call sites.
  • Added base/scenario tests and a feature-test contract + scenario to exercise the new math APIs.

Reviewed changes

Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
framework/scenario/tests/math_managed_test.rs Adds scenario-level tests for math APIs using managed types.
framework/base/tests/math_test.rs Adds base unit tests for linear interpolation and weighted average functions.
framework/base/src/types/math_util.rs Removes the old math_util module entry (logarithm code moved).
framework/base/src/types/managed/wrapped/num/big_uint.rs Updates ln() to call crate::math::internal_logarithm_i64.
framework/base/src/types/managed/wrapped/managed_decimal/managed_decimal_logarithm.rs Updates ln/log2 computations to use crate::math::internal_logarithm_i64.
framework/base/src/types.rs Stops exposing math_util from the types module tree.
framework/base/src/math/weighted_average.rs Implements weighted average helpers (including round-up variant).
framework/base/src/math/linear_interpolation.rs Implements a generic linear interpolation helper with range checking.
framework/base/src/math/internal_logarithm_i64.rs Adds internal polynomial approximation helpers for ln/log2 (i64 scaled).
framework/base/src/math.rs Defines the new math module and re-exports math helpers.
framework/base/src/lib.rs Exposes the new pub mod math at the crate root.
contracts/feature-tests/basic-features/tests/basic_features_scenario_rs_test.rs Adds a new Rust scenario test that runs math_features.scen.json.
contracts/feature-tests/basic-features/tests/basic_features_scenario_go_test.rs Adds a new Go scenario test that runs math_features.scen.json.
contracts/feature-tests/basic-features/src/math_features.rs Adds endpoints exercising the new math functions in a test contract.
contracts/feature-tests/basic-features/src/basic_features_main.rs Wires the new MathFeatures module into the basic-features contract.
contracts/feature-tests/basic-features/scenarios/math_features.scen.json Adds scenario coverage for weighted average and linear interpolation endpoints.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@andrei-marinica andrei-marinica marked this pull request as ready for review April 1, 2026 08:09
@andrei-marinica andrei-marinica merged commit 84ef63a into rc/v0.66 Apr 1, 2026
23 checks passed
@andrei-marinica andrei-marinica deleted the math-wrapper branch April 1, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants