Skip to content

Conversation

@forfudan
Copy link
Owner

This pull request introduces a module-level cache for powers of 10 in the src/decimojo/utility.mojo file. The cache is designed to store the powers of 10 up to the required value, avoiding the need to recalculate the same powers multiple times. The cache is initialized with the first value (10^0 = 1) and extended as needed.

Key changes include:

  • Module-level cache initialization:

    • Added var _power_of_10_as_uint128_cache and var _power_of_10_as_uint256_cache to store cached values of powers of 10 for UInt128 and UInt256 types, respectively.
    • Introduced _init_power_of_10_as_uint128_cache and _init_power_of_10_as_uint256_cache functions to initialize the caches with the first value (10^0 = 1).
  • Cache usage and extension:

    • Added power_of_10_as_uint128 and power_of_10_as_uint256 functions to return 10^n using cached values when available, extending the cache if necessary.

@forfudan forfudan merged commit 6be0ebe into main Mar 13, 2025
2 checks passed
@forfudan forfudan deleted the work branch March 13, 2025 21:46
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