Skip to content

Commit

Permalink
single and double precision float parsers
Browse files Browse the repository at this point in the history
the f64 parser was implemented during the GAT migration, but not the f32
one
  • Loading branch information
Geal committed Oct 21, 2023
1 parent ed9ca5b commit 934dff5
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions src/number/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ where
))
}

///todo
/// float number text parser that also recognizes "nan", "infinity" and "inf" (case insensitive)
pub fn recognize_float_or_exceptions<T, E: ParseError<T>>() -> impl Parser<T, Output = T, Error = E>
where
T: Clone + Offset,
Expand All @@ -1346,7 +1346,22 @@ where
))
}

/// TODO
/// single precision floating point number parser from text
pub fn float<T, E: ParseError<T>>() -> impl Parser<T, Output = f32, Error = E>
where
T: Clone + Offset,
T: Input + crate::traits::ParseTo<f32> + Compare<&'static str>,
<T as Input>::Item: AsChar + Clone,
T: AsBytes,
T: for<'a> Compare<&'a [u8]>,
{
Float {
o: PhantomData,
e: PhantomData,
}
}

/// double precision floating point number parser from text
pub fn double<T, E: ParseError<T>>() -> impl Parser<T, Output = f64, Error = E>
where
T: Clone + Offset,
Expand All @@ -1355,23 +1370,27 @@ where
T: AsBytes,
T: for<'a> Compare<&'a [u8]>,
{
Double { e: PhantomData }
Float {
o: PhantomData,
e: PhantomData,
}
}

/// TODO
struct Double<E> {
/// f64 parser from text
struct Float<O, E> {
o: PhantomData<O>,
e: PhantomData<E>,
}

impl<I, E: ParseError<I>> Parser<I> for Double<E>
impl<I, O, E: ParseError<I>> Parser<I> for Float<O, E>
where
I: Clone + Offset,
I: Input + crate::traits::ParseTo<f64> + Compare<&'static str>,
I: Input + crate::traits::ParseTo<O> + Compare<&'static str>,
<I as Input>::Item: AsChar + Clone,
I: AsBytes,
I: for<'a> Compare<&'a [u8]>,
{
type Output = f64;
type Output = O;
type Error = E;

fn process<OM: crate::OutputMode>(
Expand Down

0 comments on commit 934dff5

Please sign in to comment.