Sets the $err
register to true
whenever unsafe math occurs.
WARNING:
Don’t forget to call
enable_panic_on_unsafe_math
orset_flags
after performing the operations for which you disabled the defaultpanic-on-unsafe-math
behavior in the first place!
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);
}