From a2337f392b4023f489b9c43b1715d3a227c812c6 Mon Sep 17 00:00:00 2001 From: Yoan Lecoq Date: Thu, 18 Jan 2018 08:44:05 +0100 Subject: [PATCH] Document panic cases where T doesn't support NaN --- src/real.rs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/real.rs b/src/real.rs index aedceb2..e7213e7 100644 --- a/src/real.rs +++ b/src/real.rs @@ -273,7 +273,10 @@ pub trait Real /// Take the square root of a number. /// /// Returns NaN if `self` is a negative floating-point number. - /// If `self` is negative, but not floating-point, the implementation may panic. + /// + /// # Panics + /// + /// If the implementing type doesn't support NaN, this method should panic if `self < 0`. /// /// ``` /// use num_traits::real::Real; @@ -320,6 +323,10 @@ pub trait Real /// Returns the natural logarithm of the number. /// + /// # Panics + /// + /// If `self <= 0` and this type does not support a NaN representation, this function should panic. + /// /// ``` /// use num_traits::real::Real; /// @@ -336,6 +343,10 @@ pub trait Real /// Returns the logarithm of the number with respect to an arbitrary base. /// + /// # Panics + /// + /// If `self <= 0` and this type does not support a NaN representation, this function should panic. + /// /// ``` /// use num_traits::real::Real; /// @@ -355,6 +366,10 @@ pub trait Real /// Returns the base 2 logarithm of the number. /// + /// # Panics + /// + /// If `self <= 0` and this type does not support a NaN representation, this function should panic. + /// /// ``` /// use num_traits::real::Real; /// @@ -369,6 +384,11 @@ pub trait Real /// Returns the base 10 logarithm of the number. /// + /// # Panics + /// + /// If `self <= 0` and this type does not support a NaN representation, this function should panic. + /// + /// /// ``` /// use num_traits::real::Real; /// @@ -535,6 +555,11 @@ pub trait Real /// the range [-pi/2, pi/2] or NaN if the number is outside the range /// [-1, 1]. /// + /// # Panics + /// + /// If this type does not support a NaN representation, this function should panic + /// if the number is outside the range [-1, 1]. + /// /// ``` /// use num_traits::real::Real; /// use std::f64; @@ -552,6 +577,11 @@ pub trait Real /// the range [0, pi] or NaN if the number is outside the range /// [-1, 1]. /// + /// # Panics + /// + /// If this type does not support a NaN representation, this function should panic + /// if the number is outside the range [-1, 1]. + /// /// ``` /// use num_traits::real::Real; /// use std::f64; @@ -645,6 +675,11 @@ pub trait Real /// Returns `ln(1+n)` (natural logarithm) more accurately than if /// the operations were performed separately. /// + /// # Panics + /// + /// If this type does not support a NaN representation, this function should panic + /// if `self-1 <= 0`. + /// /// ``` /// use num_traits::real::Real; /// use std::f64;