-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
seq: parse "infinity" and "-infinity" #5124
Conversation
Hmm, I wonder if this is actually better? I think the comment in the code might have expected the parsing to simplify more than it actually did. The original is pretty clear and does not do redundant parsing of the float. Maybe we can refactor the original to something like this: let float_val = match s.to_ascii_lowercase() {
"inf" => ExtendedBigDecimal::Infinity,
"-inf" => ExtendedBigDecimal::MinusInfinity,
"nan" | "-nan" => return Err(ParseNumberError::Nan),
_ => return Err(ParseNumberError::Float)
};
Ok(PreciseNumber::new(float_val, 0, 0)) |
im just assuming floating point comparison to be cheaper than string comparison. Its just unfortunate that the code doesn't look as clean because match statement is unusable in this case. |
I'm not so sure actually, because the floating point parsing needs to do string comparisons as well to parse it in the first place. Even though it does it in a clever way: https://doc.rust-lang.org/src/core/num/dec2flt/parse.rs.html#200-243. In any case, if it's just for performance reasons, we need to back it up with benchmarks. |
I did some benchmarking and looks like theres no noticeable speed improvement. However, the current code still fails when given "infinty" and "-infinity" as arguments which can be fixed with this pr. |
GNU testsuite comparison:
|
GNU testsuite comparison:
|
Good catch on the Why do you think this is better than string comparison? |
I don't necessarily think one is better than the other. Scratch what i said about float vs string comparison. |
I wrote that comment originally, but now that I'm looking at it, I also agree with @tertsdiepraam that it's not really any more practical to use |
@jfinkels thanks for the input, i have updated the code |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks! I'm rerunning the FreeBSD because something is up with it, but it looks ready!
No description provided.