aldanor / fast-float-rust

Super-fast float parser in Rust (now part of Rust core)
https://docs.rs/fast-float
Apache License 2.0
275 stars 20 forks source link

How to know the parsed digits is an integer? #14

Closed J-F-Liu closed 3 years ago

J-F-Liu commented 3 years ago

i.e. there is no '.' or 'e' in the literal.

aldanor commented 3 years ago

Why, what's the use case? You don't, this information is not exported by the parser as it's not very useful.

lemire commented 3 years ago

If you write, say, a CSV or JSON parser, you may want to be able to know about the data type. E.g., in some systems "1.0" and "1" are to be treated differently. It is a niche use case, one where you need to determine the type dynamically, but it is not unreasonnable. Note that you would like the integer value (if it is an integer value) to be returned as an integer type so that you parse integers that would not fit in a floating-point type.

aldanor commented 3 years ago

Closing this for now as it's outside of this crate's functionality.

(As a workaround for your use case - you could always check if there's a ., e or E in the source byte string, it should be very fast compared to the time spent actually parsing the float)

lemire commented 3 years ago

It seems likely that one could build a derived crate which implements this functionality.