You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
in typst floats are 64 bits, meaning we should be able to handle large numbers such as 10e300. Unfortunately oxifmt is doing a computation that goes out of bounds that prevents writing the typst code:
#strfmt("{0:e}",10000000000000000000)
In my case I'm reading numbers from a json file in typst and using strfmt to display them. Can you fix this?
error: the result is too large
┌─ @preview/oxifmt:0.2.1/oxifmt.typ:228:21
│
228 │ let mantissa = f / calc.pow(10, exponent)
│ ^^^^^^^^^^^^^^^^^^^^^^
help: error occurred in this call of function `_strfmt_exp-format`
┌─ @preview/oxifmt:0.2.1/oxifmt.typ:374:20
│
374 │ replacement = _strfmt_exp-format(calc.abs(replacement), exponent-sign: exponent-sign, precision: precision)
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The text was updated successfully, but these errors were encountered:
#let toMathRepresentation(number, digits: 2) = {
if (type(number) != "float" and type(number) != "int") {
[N/A]
} else {
// Define the maximum exponent to prevent overflow
let max_exponent = 308;
// Calculate the exponent
let exponent = calc.floor(calc.log(calc.abs(number)));
if exponent > max_exponent {
"Infinity"
} else {
// Initialize mantissa
let scaled_number = calc.abs(number);
let remaining_exponent = exponent;
// Scale down by powers of 10 within Typst's limits
while remaining_exponent > 0 {
// Determine the largest power of 10 we can divide by without overflow
let scale_down = calc.min(remaining_exponent, 18);
scaled_number = scaled_number / calc.pow(10, scale_down);
remaining_exponent -= scale_down;
}
// Once scaled, the result is within [1, 10), so this is our mantissa
let mantissa = scaled_number;
// Round the mantissa to the specified number of digits
let rounded_mantissa = calc.round(mantissa*calc.pow(10,digits))/calc.pow(10,digits);
// Format the result
[$#rounded_mantissa times 10^(#exponent)$]
}
}
};
in typst floats are 64 bits, meaning we should be able to handle large numbers such as 10e300. Unfortunately oxifmt is doing a computation that goes out of bounds that prevents writing the typst code:
In my case I'm reading numbers from a json file in typst and using strfmt to display them. Can you fix this?
The text was updated successfully, but these errors were encountered: