MCPcopy Create free account
hub / github.com/argotorg/solidity / fixedPointType

Method fixedPointType

libsolidity/ast/Types.cpp:1234–1270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1232}
1233
1234FixedPointType const* RationalNumberType::fixedPointType() const
1235{
1236 bool negative = (m_value < 0);
1237 unsigned fractionalDigits = 0;
1238 rational value = abs(m_value); // We care about the sign later.
1239 rational maxValue = negative ?
1240 rational(bigint(1) << 255, 1):
1241 rational((bigint(1) << 256) - 1, 1);
1242
1243 while (value * 10 <= maxValue && value.denominator() != 1 && fractionalDigits < 80)
1244 {
1245 value *= 10;
1246 fractionalDigits++;
1247 }
1248
1249 if (value > maxValue)
1250 return nullptr;
1251
1252 // This means we round towards zero for positive and negative values.
1253 bigint v = value.numerator() / value.denominator();
1254
1255 if (negative && v != 0)
1256 // modify value to satisfy bit requirements for negative numbers:
1257 // add one bit for sign and decrement because negative numbers can be larger
1258 v = (v - 1) << 1;
1259
1260 if (v > u256(-1))
1261 return nullptr;
1262
1263 unsigned totalBits = std::max(numberEncodingSize(v), 1u) * 8;
1264 solAssert(totalBits <= 256, "");
1265
1266 return TypeProvider::fixedPoint(
1267 totalBits, fractionalDigits,
1268 negative ? FixedPointType::Modifier::Signed : FixedPointType::Modifier::Unsigned
1269 );
1270}
1271
1272StringLiteralType::StringLiteralType(Literal const& _literal):
1273 m_value(_literal.value())

Callers

nothing calls this directly

Calls 2

absFunction · 0.85
numberEncodingSizeFunction · 0.85

Tested by

no test coverage detected