typed_floats/types/
mod.rs1use const_fn::const_fn;
2
3#[derive(Debug)]
5pub enum FromStrError {
6 ParseFloatError(core::num::ParseFloatError),
8 InvalidNumber(InvalidNumber),
10}
11
12impl core::fmt::Display for FromStrError {
13 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
14 match self {
15 Self::ParseFloatError(e) => write!(f, "{e}"),
16 Self::InvalidNumber(e) => write!(f, "{e}"),
17 }
18 }
19}
20
21#[cfg(feature = "std")]
22impl std::error::Error for FromStrError {}
23
24#[cfg(feature = "serde")]
25use serde::Serialize;
26
27#[derive(Debug, Eq, PartialEq)]
29pub enum InvalidNumber {
30 NaN,
32 Zero,
34 Negative,
36 Positive,
38 Infinite,
40}
41
42impl core::fmt::Display for InvalidNumber {
43 fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
44 match self {
45 Self::NaN => write!(f, "Number is NaN"),
46 Self::Zero => write!(f, "Number is zero"),
47 Self::Negative => write!(f, "Number is negative"),
48 Self::Positive => write!(f, "Number is positive"),
49 Self::Infinite => write!(f, "Number is infinite"),
50 }
51 }
52}
53
54#[cfg(feature = "std")]
55impl std::error::Error for InvalidNumber {}
56
57#[cfg_attr(feature = "serde", derive(Serialize))]
62#[derive(Debug, Copy, Clone)]
63#[repr(transparent)]
64pub struct NonNaN<T = f64>(T);
65
66#[cfg_attr(feature = "serde", derive(Serialize))]
72#[derive(Debug, Copy, Clone)]
73#[repr(transparent)]
74pub struct NonZeroNonNaN<T = f64>(T);
75
76#[cfg_attr(feature = "serde", derive(Serialize))]
82#[derive(Debug, Copy, Clone)]
83#[repr(transparent)]
84pub struct NonNaNFinite<T = f64>(T);
85
86#[cfg_attr(feature = "serde", derive(Serialize))]
93#[derive(Debug, Copy, Clone)]
94#[repr(transparent)]
95pub struct NonZeroNonNaNFinite<T = f64>(T);
96
97#[cfg_attr(feature = "serde", derive(Serialize))]
103#[derive(Debug, Copy, Clone)]
104#[repr(transparent)]
105pub struct Positive<T = f64>(T);
106
107#[cfg_attr(feature = "serde", derive(Serialize))]
113#[derive(Debug, Copy, Clone)]
114#[repr(transparent)]
115pub struct Negative<T = f64>(T);
116
117#[cfg_attr(feature = "serde", derive(Serialize))]
124#[derive(Debug, Copy, Clone)]
125#[repr(transparent)]
126pub struct PositiveFinite<T = f64>(T);
127
128#[cfg_attr(feature = "serde", derive(Serialize))]
135#[derive(Debug, Copy, Clone)]
136#[repr(transparent)]
137pub struct NegativeFinite<T = f64>(T);
138
139#[cfg_attr(feature = "serde", derive(Serialize))]
146#[derive(Debug, Copy, Clone)]
147#[repr(transparent)]
148pub struct StrictlyPositive<T = f64>(T);
149
150#[cfg_attr(feature = "serde", derive(Serialize))]
157#[derive(Debug, Copy, Clone)]
158#[repr(transparent)]
159pub struct StrictlyNegative<T = f64>(T);
160
161#[cfg_attr(feature = "serde", derive(Serialize))]
167#[derive(Debug, Copy, Clone)]
168#[repr(transparent)]
169pub struct StrictlyPositiveFinite<T = f64>(T);
170
171#[cfg_attr(feature = "serde", derive(Serialize))]
177#[derive(Debug, Copy, Clone)]
178#[repr(transparent)]
179pub struct StrictlyNegativeFinite<T = f64>(T);
180
181use crate::traits::{Max, Min};
182
183#[cfg(any(feature = "std", feature = "libm"))]
184use crate::traits::{Atan2, Copysign, DivEuclid, Hypot, Powf};
185
186#[rustversion::since(1.85)]
187use crate::traits::Midpoint;
188
189#[cfg(all(feature = "libm", not(feature = "std")))]
190#[allow(unused_imports)]
191use num_traits::Float;
192
193mod accept;
194mod f32;
195mod f64;
196mod impls;
197
198typed_floats_macros::generate_floats!();