pub fn disable_panic_on_unsafe_math() -> u64 
Expand description

Allows unsafe math operations to occur without a FuelVM panic.
Sets the $err register to true whenever unsafe math occurs.

Additional Information

WARNING:

Don’t forget to call enable_panic_on_unsafe_math or set_flags after performing the operations for which you disabled the default panic-on-unsafe-math behavior in the first place!

Returns

  • [u64] - The flag prior to disabling panic on overflow.

Examples

use std::{assert::assert, flags::{disable_panic_on_unsafe_math, enable_panic_on_unsafe_math}, registers::error};

fn main() {
    disable_panic_on_unsafe_math();

    // Division by zero is considered unsafe math.
    let bar = 1 / 0;
    // Error flag is set to true whenever unsafe math occurs. Here represented as 1.
    assert(error() == 1);

    enable_panic_on_unsafe_math();
}
use std::{assert::assert, flags::{disable_panic_on_unsafe_math, set_flags}, registers::error};

fn foo() {
    let prior_flags = disable_panic_on_unsafe_math();

    // Division by zero is considered unsafe math.
    let bar = 1 / 0;
    // Error flag is set to true whenever unsafe math occurs. Here represented as 1.
    assert(error() == 1);

    set_flags(prior_flags);
}