Skip to content
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

rand_distr: fix no_std build #1208

Merged
merged 3 commits into from Jan 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions rand_distr/CHANGELOG.md
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.3] - 2021-12-30
- Fix `no_std` build (#1208)

## [0.4.2] - 2021-09-18
- New `Zeta` and `Zipf` distributions (#1136)
- New `SkewNormal` distribution (#1149)
Expand Down
2 changes: 1 addition & 1 deletion rand_distr/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "rand_distr"
version = "0.4.2"
version = "0.4.3"
authors = ["The Rand Project Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand Down
2 changes: 2 additions & 0 deletions rand_distr/src/binomial.rs
Expand Up @@ -13,6 +13,8 @@ use crate::{Distribution, Uniform};
use rand::Rng;
use core::fmt;
use core::cmp::Ordering;
#[allow(unused_imports)]
use num_traits::Float;
Copy link
Member Author

@newpavlov newpavlov Dec 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allow attributes is a bit unfortunate, but we currently don't have a way of checking whether std is enabled for current build, note that it's not equivalent to checking feature = "std".


/// The binomial distribution `Binomial(n, p)`.
///
Expand Down
2 changes: 2 additions & 0 deletions rand_distr/src/geometric.rs
Expand Up @@ -3,6 +3,8 @@
use crate::Distribution;
use rand::Rng;
use core::fmt;
#[allow(unused_imports)]
use num_traits::Float;

/// The geometric distribution `Geometric(p)` bounded to `[0, u64::MAX]`.
///
Expand Down
2 changes: 2 additions & 0 deletions rand_distr/src/hypergeometric.rs
Expand Up @@ -4,6 +4,8 @@ use crate::Distribution;
use rand::Rng;
use rand::distributions::uniform::Uniform;
use core::fmt;
#[allow(unused_imports)]
use num_traits::Float;

#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
Expand Down
3 changes: 2 additions & 1 deletion rand_distr/src/utils.rs
Expand Up @@ -11,6 +11,7 @@
use crate::ziggurat_tables;
use rand::distributions::hidden_export::IntoFloat;
use rand::Rng;
use num_traits::Float;

/// Calculates ln(gamma(x)) (natural logarithm of the gamma
/// function) using the Lanczos approximation.
Expand All @@ -25,7 +26,7 @@ use rand::Rng;
/// `Ag(z)` is an infinite series with coefficients that can be calculated
/// ahead of time - we use just the first 6 terms, which is good enough
/// for most purposes.
pub(crate) fn log_gamma<F: num_traits::Float>(x: F) -> F {
pub(crate) fn log_gamma<F: Float>(x: F) -> F {
// precalculated 6 coefficients for the first 6 terms of the series
let coefficients: [F; 6] = [
F::from(76.18009172947146).unwrap(),
Expand Down