Update dependency, and remove no-std functionality, to prepare to add threaded benchmarks
This commit is contained in:
parent
5e0844006e
commit
8f43327b54
@ -1,15 +1,15 @@
|
||||
[package]
|
||||
name = "rusty-fib-facts"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
authors = ["Timothy J Warren <tim@timshomepage.net>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
||||
[dev-dependencies]
|
||||
criterion = "0.3"
|
||||
criterion = { version="0.3.5", features=["html_reports"] }
|
||||
|
||||
[[bench]]
|
||||
name = "stock_functions"
|
||||
|
23
src/lib.rs
23
src/lib.rs
@ -1,21 +1,12 @@
|
||||
//! # Rusty Fib Facts
|
||||
//!
|
||||
//! Implementations of common math algorithms to benchmark
|
||||
//! Implementations of common algorithms to benchmark
|
||||
#![forbid(unsafe_code)]
|
||||
#![no_std]
|
||||
|
||||
use core::cmp::{max, min};
|
||||
pub mod parallel;
|
||||
|
||||
#[cfg(all(feature = "alloc", not(feature = "std")))]
|
||||
#[macro_use]
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[macro_use]
|
||||
extern crate std;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use core::f64::consts::{E, PI};
|
||||
use std::cmp::{max, min};
|
||||
use std::f64::consts::{E, PI};
|
||||
|
||||
/// Calculate a number in the fibonacci sequence,
|
||||
/// using recursion and a lookup table
|
||||
@ -150,7 +141,7 @@ pub fn it_factorial(n: usize) -> Option<u128> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Calculate the value of a factorial recrursively
|
||||
/// Calculate the value of a factorial recursively
|
||||
///
|
||||
/// Can calculate up to 34! using native unsigned 128 bit integers.
|
||||
///
|
||||
@ -191,7 +182,6 @@ pub fn factorial(n: usize) -> Option<u128> {
|
||||
/// let invalid = approx_factorial(171.0); // None
|
||||
/// # assert!(invalid.is_none());
|
||||
/// ```
|
||||
#[cfg(feature = "std")]
|
||||
#[inline]
|
||||
pub fn approx_factorial(n: f64) -> Option<f64> {
|
||||
let power = (n / E).powf(n);
|
||||
@ -199,7 +189,7 @@ pub fn approx_factorial(n: f64) -> Option<f64> {
|
||||
|
||||
let res = power * root;
|
||||
|
||||
if res >= core::f64::MIN && res <= core::f64::MAX {
|
||||
if res >= std::f64::MIN && res <= std::f64::MAX {
|
||||
Some(res)
|
||||
} else {
|
||||
None
|
||||
@ -335,7 +325,6 @@ mod tests {
|
||||
assert!(it_factorial(35).is_none());
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
#[test]
|
||||
fn test_approx_factorial() {
|
||||
assert!(approx_factorial(170.624).is_some());
|
||||
|
Loading…
Reference in New Issue
Block a user