Add no_std support and testing
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2020-04-16 14:07:12 -04:00
parent bbfada5c0f
commit 3f6071d196
5 changed files with 41 additions and 3 deletions

View File

@ -11,6 +11,11 @@ edition = "2018"
[dev-dependencies]
criterion = "0.3"
[features]
default = ["std"]
alloc = []
std = ["alloc"]
[[bench]]
name = "stock_functions"
harness = false

10
Jenkinsfile vendored
View File

@ -16,6 +16,16 @@ pipeline {
sh "cargo test"
}
}
stage('Check no_std') {
steps {
sh "cargo check --no-default-features --features alloc"
}
}
stage('Test no_std') {
steps {
sh "cargo test --no-default-features --features alloc"
}
}
stage('Coverage') {
steps {
sh "cargo clean"

View File

@ -2,6 +2,17 @@
//! \[WIP\] Arbitrarily large integers
use crate::num::Sign::*;
use crate::num::*;
#[cfg(all(feature = "alloc", not(feature = "std")))]
extern crate alloc;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::vec::*;
#[cfg(all(feature = "alloc", not(feature = "std")))]
use alloc::string::*;
#[cfg(feature = "std")]
use std::prelude::v1::*;
use core::convert::TryInto;
use core::mem::replace;
use core::ops::{

View File

@ -2,8 +2,18 @@
//!
//! Playin' with Numerics in Rust
#![forbid(unsafe_code)]
#![no_std]
use std::f64::consts::{E, PI};
#[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};
pub mod bigint;
pub mod num;
@ -183,6 +193,7 @@ 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);
@ -233,6 +244,7 @@ mod tests {
assert!(it_factorial(35).is_none());
}
#[cfg(feature = "std")]
#[test]
fn test_approx_factorial() {
assert!(approx_factorial(170.624).is_some());

View File

@ -2,8 +2,8 @@
use crate::num::Sign::*;
use crate::num::*;
use std::cmp::{Ord, Ordering, PartialOrd};
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use core::cmp::{Ord, Ordering, PartialOrd};
use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
/// Type representing a fraction
///