Skip to content

Commit 18b9ede

Browse files
committed
miri: shims for erf & friends
1 parent b8f0ed3 commit 18b9ede

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

src/tools/miri/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![feature(rustc_private)]
33
#![feature(cell_update)]
44
#![feature(float_gamma)]
5+
#![feature(float_erf)]
56
#![feature(map_try_insert)]
67
#![feature(never_type)]
78
#![feature(try_blocks)]

src/tools/miri/src/shims/foreign_items.rs

+8
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
742742
| "log1pf"
743743
| "expm1f"
744744
| "tgammaf"
745+
| "erff"
746+
| "erfcf"
745747
=> {
746748
let [f] = this.check_shim(abi, Conv::C , link_name, args)?;
747749
let f = this.read_scalar(f)?.to_f32()?;
@@ -759,6 +761,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
759761
"log1pf" => f_host.ln_1p(),
760762
"expm1f" => f_host.exp_m1(),
761763
"tgammaf" => f_host.gamma(),
764+
"erff" => f_host.erf(),
765+
"erfcf" => f_host.erfc(),
762766
_ => bug!(),
763767
};
764768
let res = res.to_soft();
@@ -799,6 +803,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
799803
| "log1p"
800804
| "expm1"
801805
| "tgamma"
806+
| "erf"
807+
| "erfc"
802808
=> {
803809
let [f] = this.check_shim(abi, Conv::C , link_name, args)?;
804810
let f = this.read_scalar(f)?.to_f64()?;
@@ -816,6 +822,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
816822
"log1p" => f_host.ln_1p(),
817823
"expm1" => f_host.exp_m1(),
818824
"tgamma" => f_host.gamma(),
825+
"erf" => f_host.erf(),
826+
"erfc" => f_host.erfc(),
819827
_ => bug!(),
820828
};
821829
let res = res.to_soft();

src/tools/miri/tests/pass/float.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(stmt_expr_attributes)]
2+
#![feature(float_erf)]
23
#![feature(float_gamma)]
34
#![feature(core_intrinsics)]
45
#![feature(f128)]
@@ -1076,6 +1077,11 @@ pub fn libm() {
10761077
let (val, sign) = (-0.5f64).ln_gamma();
10771078
assert_approx_eq!(val, (2.0 * f64::consts::PI.sqrt()).ln());
10781079
assert_eq!(sign, -1);
1080+
1081+
assert_approx_eq!(1.0f32.erf(), 0.84270079294971486934122063508260926f32);
1082+
assert_approx_eq!(1.0f64.erf(), 0.84270079294971486934122063508260926f64);
1083+
assert_approx_eq!(1.0f32.erfc(), 0.15729920705028513065877936491739074f32);
1084+
assert_approx_eq!(1.0f64.erfc(), 0.15729920705028513065877936491739074f64);
10791085
}
10801086

10811087
fn test_fast() {

0 commit comments

Comments
 (0)