Parse the scientific notation component of a float.
fn parseScientific(stream: *FloatStream) ?i64
fn parseScientific(stream: *FloatStream) ?i64 {
var exponent: i64 = 0;
var negative = false;
if (stream.first()) |c| {
negative = c == '-';
if (c == '-' or c == '+') {
stream.advance(1);
}
}
if (stream.firstIsDigit(10)) {
while (stream.scanDigit(10)) |digit| {
// no overflows here, saturate well before overflow
if (exponent < 0x1000_0000) {
exponent = 10 * exponent + digit;
}
}
return if (negative) -exponent else exponent;
}
return null;
}