Update dependency, and remove no-std functionality, to prepare to add threaded benchmarks

This commit is contained in:
Timothy Warren 2022-03-11 13:05:29 -05:00
parent 5e0844006e
commit 8f43327b54
2 changed files with 9 additions and 20 deletions

View File

@ -1,15 +1,15 @@
[package] [package]
name = "rusty-fib-facts" name = "rusty-fib-facts"
version = "0.1.0" version = "0.2.0"
authors = ["Timothy J Warren <tim@timshomepage.net>"] 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 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
[dev-dependencies] [dev-dependencies]
criterion = "0.3" criterion = { version="0.3.5", features=["html_reports"] }
[[bench]] [[bench]]
name = "stock_functions" name = "stock_functions"

View File

@ -1,21 +1,12 @@
//! # Rusty Fib Facts //! # Rusty Fib Facts
//! //!
//! Implementations of common math algorithms to benchmark //! Implementations of common algorithms to benchmark
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
#![no_std]
use core::cmp::{max, min}; pub mod parallel;
#[cfg(all(feature = "alloc", not(feature = "std")))] use std::cmp::{max, min};
#[macro_use] use std::f64::consts::{E, PI};
extern crate alloc;
#[cfg(feature = "std")]
#[macro_use]
extern crate std;
#[cfg(feature = "std")]
use core::f64::consts::{E, PI};
/// Calculate a number in the fibonacci sequence, /// Calculate a number in the fibonacci sequence,
/// using recursion and a lookup table /// 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. /// 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 /// let invalid = approx_factorial(171.0); // None
/// # assert!(invalid.is_none()); /// # assert!(invalid.is_none());
/// ``` /// ```
#[cfg(feature = "std")]
#[inline] #[inline]
pub fn approx_factorial(n: f64) -> Option<f64> { pub fn approx_factorial(n: f64) -> Option<f64> {
let power = (n / E).powf(n); let power = (n / E).powf(n);
@ -199,7 +189,7 @@ pub fn approx_factorial(n: f64) -> Option<f64> {
let res = power * root; let res = power * root;
if res >= core::f64::MIN && res <= core::f64::MAX { if res >= std::f64::MIN && res <= std::f64::MAX {
Some(res) Some(res)
} else { } else {
None None
@ -335,7 +325,6 @@ mod tests {
assert!(it_factorial(35).is_none()); assert!(it_factorial(35).is_none());
} }
#[cfg(feature = "std")]
#[test] #[test]
fn test_approx_factorial() { fn test_approx_factorial() {
assert!(approx_factorial(170.624).is_some()); assert!(approx_factorial(170.624).is_some());