Add sanity test to verify floating point std math lib works for BPF (#21013)

On-chain programs frequently require floating point operations. In
addition standard library functions are expected to be available.
This change adds a simple sanity check that such functions are
available and work correctly when compiled to BPF.
This commit is contained in:
Dmitri Makarov
2021-11-02 17:09:58 -07:00
committed by GitHub
parent 1adf255e3a
commit 346cb9a275
2 changed files with 10 additions and 1 deletions

View File

@ -62,6 +62,15 @@ pub fn process_instruction(
panic!();
}
{
// Test - float math functions
let zero = accounts[0].try_borrow_mut_data()?.len() as f64;
let num = zero + 8.0f64;
let num = num.powf(0.333f64);
// check that the result is in a correct interval close to 1.998614185980905
assert!(1.9986f64 < num && num < 2.0f64);
}
sol_log_compute_units();
Ok(())
}