Skip to content

Commit

Permalink
wip on float
Browse files Browse the repository at this point in the history
  • Loading branch information
thedavidmeister committed Aug 16, 2024
1 parent 84a9b82 commit 98f74c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/generated/RainterpreterParserNPE2.pointers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
pragma solidity =0.8.25;

/// @dev Hash of the known bytecode.
bytes32 constant BYTECODE_HASH = bytes32(0x9dc8d07f99b6134659f649d06710097ca77214e78f1cb5ccef5ae0a063dc77e2);
bytes32 constant BYTECODE_HASH = bytes32(0x11aba6006d98ab79c4372ab4f0d673880a1efc51f9c1f901f06e706029c052d7);

/// @dev The parse meta that is used to lookup word definitions.
/// The structure of the parse meta is:
Expand Down Expand Up @@ -38,11 +38,11 @@ uint8 constant PARSE_META_BUILD_DEPTH = 2;
/// These positional indexes all map to the same indexes looked up in the parse
/// meta.
bytes constant OPERAND_HANDLER_FUNCTION_POINTERS =
hex"173517351735179a181318131813179a179a173517351735181318131813181318131813";
hex"13ef13ef13ef145414cd14cd14cd1454145413ef13ef13ef14cd14cd14cd14cd14cd14cd";

/// @dev Every two bytes is a function pointer for a literal parser.
/// Literal dispatches are determined by the first byte(s) of the literal
/// rather than a full word lookup, and are done with simple conditional
/// jumps as the possibilities are limited compared to the number of words we
/// have.
bytes constant LITERAL_PARSER_FUNCTION_POINTERS = hex"0dab1073147a1554";
bytes constant LITERAL_PARSER_FUNCTION_POINTERS = hex"0dab1073112411fe";
2 changes: 1 addition & 1 deletion src/lib/op/LibAllStandardOpsNP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ library LibAllStandardOpsNP {
memory pointersFixed = [
lengthPointer,
LibParseLiteralHex.parseHex,
LibParseLiteralDecimal.parseDecimal,
LibParseLiteralDecimal.parseDecimalFloatPacked,
LibParseLiteralString.parseString,
LibParseLiteralSubParseable.parseSubParseable
];
Expand Down
17 changes: 17 additions & 0 deletions src/lib/parse/literal/LibParseLiteralDecimal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from "../LibParseCMask.sol";
import {LibParseError} from "../LibParseError.sol";
import {LibParse} from "../LibParse.sol";
import {LibDecimalFloatImplementation, LibDecimalFloat} from "rain.math.float/src/lib/LibDecimalFloat.sol";

/// @dev The default is 18 decimal places for a fractional number.
uint256 constant DECIMAL_SCALE = 18;
Expand Down Expand Up @@ -115,6 +116,22 @@ library LibParseLiteralDecimal {
}
}

function parseDecimalFloatPacked(ParseState memory state, uint256 start, uint256 end)
internal
pure
returns (uint256 cursor, uint256 packedFloat)
{
int256 signedCoefficient;
int256 exponent;
(cursor, signedCoefficient, exponent) = parseDecimalFloat(state, start, end);
(int256 normalizedSignedCoefficient, int256 normalizedExponent) =
LibDecimalFloatImplementation.normalize(signedCoefficient, exponent);
if (!LibDecimalFloat.eq(normalizedSignedCoefficient, normalizedExponent, signedCoefficient, exponent)) {
revert DecimalLiteralPrecisionLoss(state.parseErrorOffset(start));
}
packedFloat = LibDecimalFloat.pack(normalizedSignedCoefficient, normalizedExponent);
}

function parseDecimalFloat(ParseState memory state, uint256 start, uint256 end)
internal
pure
Expand Down

0 comments on commit 98f74c2

Please sign in to comment.