Skip to content
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

Adds support for exponential notation like 1e10 => 10000000000 #69

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dannyvankooten
Copy link

Closes #68

Comment on lines +247 to +250
while let Some(next) = chars.peek() {
if !matches!(*next, '0'..='9') {
break;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can use .next_if instead.


if num_vec.len() > 0 {
if let Some(exp) = num_vec.parse::<usize>().ok() {
result.push(Token::Num(x * pow(10 as f64, exp) as f64));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't using num::pow directly be better?

Suggested change
result.push(Token::Num(x * pow(10 as f64, exp) as f64));
result.push(Token::Num(x * num::pow(10 as f64, exp) as f64));

chars.next();
}

if num_vec.len() > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if num_vec.len() > 0 {
if !num_vec.is_empty() {

Comment on lines +290 to +294
#[test]
fn eval_exponential_notation_decimal() {
let evaled = eval("2.5e5", None);
assert_eq!(evaled, Ok(250000.0));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please try this too? 5e5e5.

@AmeerTaweel
Copy link

@dannyvankooten Any updates on this?

@pickfire
Copy link
Collaborator

@AmeerTaweel I think you can just create a PR to supersede this pull request, the author might be busy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support for exponential notation
3 participants