Skip to content

Commit a2337f3

Browse files
committed
Document panic cases where T doesn't support NaN
1 parent ddd664a commit a2337f3

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/real.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,10 @@ pub trait Real
273273
/// Take the square root of a number.
274274
///
275275
/// Returns NaN if `self` is a negative floating-point number.
276-
/// If `self` is negative, but not floating-point, the implementation may panic.
276+
///
277+
/// # Panics
278+
///
279+
/// If the implementing type doesn't support NaN, this method should panic if `self < 0`.
277280
///
278281
/// ```
279282
/// use num_traits::real::Real;
@@ -320,6 +323,10 @@ pub trait Real
320323

321324
/// Returns the natural logarithm of the number.
322325
///
326+
/// # Panics
327+
///
328+
/// If `self <= 0` and this type does not support a NaN representation, this function should panic.
329+
///
323330
/// ```
324331
/// use num_traits::real::Real;
325332
///
@@ -336,6 +343,10 @@ pub trait Real
336343

337344
/// Returns the logarithm of the number with respect to an arbitrary base.
338345
///
346+
/// # Panics
347+
///
348+
/// If `self <= 0` and this type does not support a NaN representation, this function should panic.
349+
///
339350
/// ```
340351
/// use num_traits::real::Real;
341352
///
@@ -355,6 +366,10 @@ pub trait Real
355366

356367
/// Returns the base 2 logarithm of the number.
357368
///
369+
/// # Panics
370+
///
371+
/// If `self <= 0` and this type does not support a NaN representation, this function should panic.
372+
///
358373
/// ```
359374
/// use num_traits::real::Real;
360375
///
@@ -369,6 +384,11 @@ pub trait Real
369384

370385
/// Returns the base 10 logarithm of the number.
371386
///
387+
/// # Panics
388+
///
389+
/// If `self <= 0` and this type does not support a NaN representation, this function should panic.
390+
///
391+
///
372392
/// ```
373393
/// use num_traits::real::Real;
374394
///
@@ -535,6 +555,11 @@ pub trait Real
535555
/// the range [-pi/2, pi/2] or NaN if the number is outside the range
536556
/// [-1, 1].
537557
///
558+
/// # Panics
559+
///
560+
/// If this type does not support a NaN representation, this function should panic
561+
/// if the number is outside the range [-1, 1].
562+
///
538563
/// ```
539564
/// use num_traits::real::Real;
540565
/// use std::f64;
@@ -552,6 +577,11 @@ pub trait Real
552577
/// the range [0, pi] or NaN if the number is outside the range
553578
/// [-1, 1].
554579
///
580+
/// # Panics
581+
///
582+
/// If this type does not support a NaN representation, this function should panic
583+
/// if the number is outside the range [-1, 1].
584+
///
555585
/// ```
556586
/// use num_traits::real::Real;
557587
/// use std::f64;
@@ -645,6 +675,11 @@ pub trait Real
645675
/// Returns `ln(1+n)` (natural logarithm) more accurately than if
646676
/// the operations were performed separately.
647677
///
678+
/// # Panics
679+
///
680+
/// If this type does not support a NaN representation, this function should panic
681+
/// if `self-1 <= 0`.
682+
///
648683
/// ```
649684
/// use num_traits::real::Real;
650685
/// use std::f64;

0 commit comments

Comments
 (0)