Skip to content

Commit

Permalink
miri: shims for erf & friends
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigorenkoPV committed Feb 14, 2025
1 parent b8f0ed3 commit 18b9ede
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/tools/miri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![feature(rustc_private)]
#![feature(cell_update)]
#![feature(float_gamma)]
#![feature(float_erf)]
#![feature(map_try_insert)]
#![feature(never_type)]
#![feature(try_blocks)]
Expand Down
8 changes: 8 additions & 0 deletions src/tools/miri/src/shims/foreign_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
| "log1pf"
| "expm1f"
| "tgammaf"
| "erff"
| "erfcf"
=> {
let [f] = this.check_shim(abi, Conv::C , link_name, args)?;
let f = this.read_scalar(f)?.to_f32()?;
Expand All @@ -759,6 +761,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
"log1pf" => f_host.ln_1p(),
"expm1f" => f_host.exp_m1(),
"tgammaf" => f_host.gamma(),
"erff" => f_host.erf(),
"erfcf" => f_host.erfc(),
_ => bug!(),
};
let res = res.to_soft();
Expand Down Expand Up @@ -799,6 +803,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
| "log1p"
| "expm1"
| "tgamma"
| "erf"
| "erfc"
=> {
let [f] = this.check_shim(abi, Conv::C , link_name, args)?;
let f = this.read_scalar(f)?.to_f64()?;
Expand All @@ -816,6 +822,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
"log1p" => f_host.ln_1p(),
"expm1" => f_host.exp_m1(),
"tgamma" => f_host.gamma(),
"erf" => f_host.erf(),
"erfc" => f_host.erfc(),
_ => bug!(),
};
let res = res.to_soft();
Expand Down
6 changes: 6 additions & 0 deletions src/tools/miri/tests/pass/float.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(stmt_expr_attributes)]
#![feature(float_erf)]
#![feature(float_gamma)]
#![feature(core_intrinsics)]
#![feature(f128)]
Expand Down Expand Up @@ -1076,6 +1077,11 @@ pub fn libm() {
let (val, sign) = (-0.5f64).ln_gamma();
assert_approx_eq!(val, (2.0 * f64::consts::PI.sqrt()).ln());
assert_eq!(sign, -1);

assert_approx_eq!(1.0f32.erf(), 0.84270079294971486934122063508260926f32);
assert_approx_eq!(1.0f64.erf(), 0.84270079294971486934122063508260926f64);
assert_approx_eq!(1.0f32.erfc(), 0.15729920705028513065877936491739074f32);
assert_approx_eq!(1.0f64.erfc(), 0.15729920705028513065877936491739074f64);
}

fn test_fast() {
Expand Down

0 comments on commit 18b9ede

Please sign in to comment.