Skip to content

improve usability #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# rust-strictmath
This crate is inspired by java [StrictMath](https://github.com/openjdk/jdk/blob/jdk8-b120/jdk/src/share/native/java/lang/StrictMath.c). If obtaining a completely predictable result is more important than running speed, then the crate should be used.This crate provide series of float functions to ensure they could produce the same results across different platforms. These algorithms are available from the well-known network library netlib as the package "Freely Distributable Math Library," [fdlibm](https://netlib.org/fdlibm/).

# function list
- acos
- asin
- atan
- atan2
- cbrt
- cosh
- expm1
- hypot
- log1p
- sinh
- tan
- tanh

# Usage

Expand Down
105 changes: 52 additions & 53 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,63 +1,62 @@
mod strict_math;

pub use strict_math::racos;
pub use strict_math::rasin;
pub use strict_math::ratan;
pub use strict_math::ratan2;
pub use strict_math::rcbrt;
pub use strict_math::rcosh;
pub use strict_math::rexpm1;
pub use strict_math::rhypot;
pub use strict_math::rlog1p;
pub use strict_math::rsinh;
pub use strict_math::rtan;
pub use strict_math::rtanh;
pub use strict_math::acos;
pub use strict_math::asin;
pub use strict_math::atan;
pub use strict_math::atan2;
pub use strict_math::cbrt;
pub use strict_math::cosh;
pub use strict_math::expm1;
pub use strict_math::hypot;
pub use strict_math::log1p;
pub use strict_math::sinh;
pub use strict_math::tan;
pub use strict_math::tanh;

mod test {
use super::*;

#[test]
pub fn test() {
unsafe {
assert_eq!(
racos(0.055605003447049994_f64),
0.055605003447049994_f64.acos()
);
assert_eq!(
rasin(0.055605003447049994_f64),
0.055605003447049994_f64.asin()
);
assert_eq!(
ratan(0.055605003447049994_f64),
0.055605003447049994_f64.atan()
);
assert_eq!(ratan2(3.0_f64, -3.0_f64), 3.0_f64.atan2(-3.0_f64));
assert_eq!(rcbrt(-0.055605003447049994_f64), -0.3816845880251514);
assert_eq!(
rcosh(0.055605003447049994_f64),
0.055605003447049994_f64.cosh()
);
assert_eq!(
rexpm1(0.055605003447049994_f64),
0.055605003447049994_f64.exp_m1()
);
assert_eq!(rhypot(2.0_f64, 3.0_f64), 2.0_f64.hypot(3.0_f64));
assert_eq!(
rlog1p(0.055605003447049994_f64),
0.055605003447049994_f64.ln_1p()
);
assert_eq!(
rsinh(0.055605003447049994_f64),
0.055605003447049994_f64.sinh()
);
assert_eq!(
rtan(0.055605003447049994_f64),
0.055605003447049994_f64.tan()
);
assert_eq!(
rtanh(0.055605003447049994_f64),
0.055605003447049994_f64.tanh()
);
}
assert_eq!(
acos(0.055605003447049994_f64),
0.055605003447049994_f64.acos()
);
assert_eq!(
asin(0.055605003447049994_f64),
0.055605003447049994_f64.asin()
);
assert_eq!(
atan(0.055605003447049994_f64),
0.055605003447049994_f64.atan()
);
assert_eq!(atan2(3.0_f64, -3.0_f64), 3.0_f64.atan2(-3.0_f64));
assert_eq!(
cosh(0.055605003447049994_f64),
0.055605003447049994_f64.cosh()
);
assert_eq!(
expm1(0.055605003447049994_f64),
0.055605003447049994_f64.exp_m1()
);
assert_eq!(hypot(2.0_f64, 3.0_f64), 2.0_f64.hypot(3.0_f64));
assert_eq!(
log1p(0.055605003447049994_f64),
0.055605003447049994_f64.ln_1p()
);
assert_eq!(
sinh(0.055605003447049994_f64),
0.055605003447049994_f64.sinh()
);
assert_eq!(
tan(0.055605003447049994_f64),
0.055605003447049994_f64.tan()
);
assert_eq!(
tanh(0.055605003447049994_f64),
0.055605003447049994_f64.tanh()
);
eprintln!("cbrt:: {}", -0.055605003447049994_f64.cbrt());
assert_eq!(cbrt(-0.055605003447049994_f64), -0.3816845880251514);
}
}
Loading