mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Fix conversion.
This commit is contained in:
parent
c4c0d0502d
commit
d33eaf48b8
@ -915,11 +915,13 @@ void CompilerUtils::convertType(
|
||||
else
|
||||
solAssert(false, "");
|
||||
|
||||
bigint factor = pow(bigint(10), static_cast<unsigned>(abs(digitDifference)));
|
||||
solAssert(0 <= factor && factor <= std::numeric_limits<u256>::max(), "");
|
||||
if (digitDifference > 0)
|
||||
m_context << pow(u256(10), static_cast<unsigned>(digitDifference)) << Instruction::MUL;
|
||||
m_context << u256(factor) << Instruction::MUL;
|
||||
else if (digitDifference < 0)
|
||||
m_context <<
|
||||
pow(u256(10), static_cast<unsigned>(-digitDifference)) <<
|
||||
u256(factor) <<
|
||||
Instruction::SWAP1 <<
|
||||
(isSigned ? Instruction::SDIV : Instruction::DIV);
|
||||
|
||||
|
@ -499,10 +499,12 @@ string YulUtilFunctions::fixedPointShiftFunction(int _digits, bool _signed)
|
||||
return m_functionCollector.createFunction(functionName, [&](vector<string>& _args, vector<string>& _ret) {
|
||||
_args = {"value"};
|
||||
_ret = {"result"};
|
||||
bigint factor = bigint("1" + string(static_cast<unsigned>(abs(_digits)), '0'));
|
||||
solAssert(factor < (bigint(1) << 256), "");
|
||||
return
|
||||
Whiskers("result := <op>(value, <factor>)")
|
||||
("op", _digits >= 0 ? "mul" : _signed ? "sdiv" : "div")
|
||||
("factor", ("1" + string(static_cast<unsigned>(abs(_digits)), '0')))
|
||||
("factor", factor.str())
|
||||
.render();
|
||||
});
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
contract C {
|
||||
function test() public pure returns (uint a) {
|
||||
ufixed256x77 x = 1.0000001234;
|
||||
return uint(x);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 0
|
Loading…
Reference in New Issue
Block a user