-
Notifications
You must be signed in to change notification settings - Fork 2
concrete mul #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
concrete mul #43
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| // SPDX-License-Identifier: CAL | ||
| pragma solidity =0.8.25; | ||
|
|
||
| import {LibDecimalFloat, Float} from "../lib/LibDecimalFloat.sol"; | ||
| import {LOG_TABLES_ADDRESS} from "../lib/deploy/LibDecimalFloatDeploy.sol"; | ||
| import {LibFormatDecimalFloat} from "../lib/format/LibFormatDecimalFloat.sol"; | ||
| import {LibParseDecimalFloat} from "../lib/parse/LibParseDecimalFloat.sol"; | ||
|
|
||
| contract DecimalFloat { | ||
| using LibDecimalFloat for Float; | ||
|
|
||
| /// Exposes `LibParseDecimalFloat.parseDecimalFloat` for offchain use. | ||
| /// @param str The string to parse. | ||
| /// @return errorSelector The selector of the error if parsing failed. `0` | ||
| /// if parsing succeeded. | ||
| /// @return parsed The parsed float. Caller MUST check `errorSelector` to | ||
| /// determine if parsing succeeded. | ||
| function parse(string memory str) external pure returns (bytes4, Float) { | ||
| (bytes4 errorSelector, Float parsed) = LibParseDecimalFloat.parseDecimalFloat(str); | ||
| return (errorSelector, parsed); | ||
| } | ||
|
|
||
| /// Exposes `LibFormatDecimalFloat.toDecimalString` for offchain use. | ||
| /// @param a The float to format. | ||
| /// @return The string representation of the float. | ||
| function format(Float a) external pure returns (string memory) { | ||
| return LibFormatDecimalFloat.toDecimalString(a); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.add` for offchain use. | ||
| /// @param a The first float to add. | ||
| /// @param b The second float to add. | ||
| /// @return The sum of the two floats. | ||
| function add(Float a, Float b) external pure returns (Float) { | ||
| return a.add(b); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.sub` for offchain use. | ||
| /// @param a The first float to subtract. | ||
| /// @param b The second float to subtract. | ||
| /// @return The difference of the two floats. | ||
| function sub(Float a, Float b) external pure returns (Float) { | ||
| return a.sub(b); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.minus` for offchain use. | ||
| /// @param a The float to negate. | ||
| /// @return The negated float. | ||
| function minus(Float a) external pure returns (Float) { | ||
| return a.minus(); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.abs` for offchain use. | ||
| /// @param a The float to get the absolute value of. | ||
| /// @return The absolute value of the float. | ||
| function abs(Float a) external pure returns (Float) { | ||
| return a.abs(); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.mul` for offchain use. | ||
| /// @param a The first float to multiply. | ||
| /// @param b The second float to multiply. | ||
| /// @return The product of the two floats. | ||
| function mul(Float a, Float b) external pure returns (Float) { | ||
| return a.mul(b); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.div` for offchain use. | ||
| /// @param a The first float to divide. | ||
| /// @param b The second float to divide. | ||
| /// @return The quotient of the two floats. | ||
| function div(Float a, Float b) external pure returns (Float) { | ||
| return a.div(b); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.inv` for offchain use. | ||
| /// @param a The float to invert. | ||
| /// @return The inverted float. | ||
| function inv(Float a) external pure returns (Float) { | ||
| return a.inv(); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.eq` for offchain use. | ||
| /// @param a The first float to compare. | ||
| /// @param b The second float to compare. | ||
| /// @return True if the two floats are equal, false otherwise. | ||
| function eq(Float a, Float b) external pure returns (bool) { | ||
| return a.eq(b); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.lt` for offchain use. | ||
| /// @param a The first float to compare. | ||
| /// @param b The second float to compare. | ||
| /// @return True if the first float is less than the second, false otherwise. | ||
| function lt(Float a, Float b) external pure returns (bool) { | ||
| return a.lt(b); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.gt` for offchain use. | ||
| /// @param a The first float to compare. | ||
| /// @param b The second float to compare. | ||
| /// @return True if the first float is greater than the second, false | ||
| /// otherwise. | ||
| function gt(Float a, Float b) external pure returns (bool) { | ||
| return a.gt(b); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.frac` for offchain use. | ||
| /// @param a The float to get the fractional part of. | ||
| /// @return The fractional part of the float. | ||
| function frac(Float a) external pure returns (Float) { | ||
| return a.frac(); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.floor` for offchain use. | ||
| /// @param a The float to get the floor of. | ||
| /// @return The floored float. | ||
| function floor(Float a) external pure returns (Float) { | ||
| return a.floor(); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.pow10` for offchain use. | ||
| /// @param a The float to raise to the power of 10. | ||
| /// @return The result of raising the float to the power of 10. | ||
| function pow10(Float a) external view returns (Float) { | ||
| return a.pow10(LOG_TABLES_ADDRESS); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.log10` for offchain use. | ||
| /// @param a The float to take the logarithm of. | ||
| /// @return The logarithm of the float. | ||
| function log10(Float a) external view returns (Float) { | ||
| return a.log10(LOG_TABLES_ADDRESS); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.pow` for offchain use. | ||
| /// @param a The base float. | ||
| /// @param b The exponent float. | ||
| /// @return The result of raising the base float to the power of the exponent | ||
| function pow(Float a, Float b) external view returns (Float) { | ||
| return a.pow(b, LOG_TABLES_ADDRESS); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.min` for offchain use. | ||
| /// @param a The first float to compare. | ||
| /// @param b The second float to compare. | ||
| /// @return The smaller of the two floats. | ||
| function min(Float a, Float b) external pure returns (Float) { | ||
| return a.min(b); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.max` for offchain use. | ||
| /// @param a The first float to compare. | ||
| /// @param b The second float to compare. | ||
| /// @return The larger of the two floats. | ||
| function max(Float a, Float b) external pure returns (Float) { | ||
| return a.max(b); | ||
| } | ||
|
|
||
| /// Exposes `LibDecimalFloat.isZero` for offchain use. | ||
| /// @param a The float to check. | ||
| /// @return True if the float is zero, false otherwise. | ||
| function isZero(Float a) external pure returns (bool) { | ||
| return a.isZero(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.