-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathLibDecimalFloat.sub.t.sol
More file actions
48 lines (41 loc) · 1.97 KB
/
Copy pathLibDecimalFloat.sub.t.sol
File metadata and controls
48 lines (41 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// SPDX-License-Identifier: LicenseRef-DCL-1.0
// SPDX-FileCopyrightText: Copyright (c) 2020 Rain Open Source Software Ltd
pragma solidity =0.8.25;
import {LibDecimalFloat, Float, EXPONENT_MIN, EXPONENT_MAX} from "src/lib/LibDecimalFloat.sol";
import {LibDecimalFloatImplementation} from "src/lib/implementation/LibDecimalFloatImplementation.sol";
import {Test} from "forge-std/Test.sol";
contract LibDecimalFloatSubTest is Test {
using LibDecimalFloat for Float;
function subExternal(int256 signedCoefficientA, int256 exponentA, int256 signedCoefficientB, int256 exponentB)
external
pure
returns (int256, int256)
{
return LibDecimalFloatImplementation.sub(signedCoefficientA, exponentA, signedCoefficientB, exponentB);
}
function subExternal(Float floatA, Float floatB) external pure returns (Float) {
return LibDecimalFloat.sub(floatA, floatB);
}
function packLossyExternal(int256 signedCoefficient, int256 exponent) external pure returns (Float, bool) {
return LibDecimalFloat.packLossy(signedCoefficient, exponent);
}
function testSubPacked(Float a, Float b) external {
(int256 signedCoefficientA, int256 exponentA) = a.unpack();
(int256 signedCoefficientB, int256 exponentB) = b.unpack();
try this.subExternal(signedCoefficientA, exponentA, signedCoefficientB, exponentB) returns (
int256 signedCoefficient, int256 exponent
) {
try this.packLossyExternal(signedCoefficient, exponent) returns (Float float, bool lossless) {
(lossless);
Float floatImplementation = this.subExternal(a, b);
assertTrue(float.eq(floatImplementation));
} catch (bytes memory err) {
vm.expectRevert(err);
this.packLossyExternal(signedCoefficient, exponent);
}
} catch (bytes memory err) {
vm.expectRevert(err);
this.subExternal(a, b);
}
}
}