mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:10:12 +01:00
Implement support for floating-point <-> integer type conversions as described in #820 and #845, extended to support `unsafe as` conversions for the conversions that can't be expressed as either implicit conversions or `as` conversions. One tricky part here is conversions from floating-point literals to integer types. Such literals may have both a very large mantissa and a corresponding somewhat large negative exponent, and still produce a result that is in the range of values that a small integer type can represent. In order to support that while avoiding building very large 2^N or 10^N constants in general, we first compute a conservative approximation of the number of bits necessary to represent the integer result, with an early exit if the number is either definitely too large or definitely zero. The remaining cases have a reasonable bound on the size of integer necessary to compute the base^exponent multiplicand. Assisted-by: Gemini via Antigravity