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

Support int and bool types #11

Closed
optozorax opened this issue Mar 15, 2021 · 2 comments
Closed

Support int and bool types #11

optozorax opened this issue Mar 15, 2021 · 2 comments

Comments

@optozorax
Copy link

optozorax commented Mar 15, 2021

It would be very nice if this crate can support these types along with their specific operations like bitwise operations (for int) or logic and/or (for bool), and equal/greater/less (for float + int → bool). And bool and float combination in rust-style: if my_bool { 1.0 } else { 0.0 } + sin(x).

@optozorax
Copy link
Author

optozorax commented Mar 16, 2021

Hmm, I managed to solve this problem by introducing this functions:

let mut cb = |name: &str, args: Vec<f64>| -> Option<f64> {
    Some(match name {
        "if" =>  if *args.get(0)? == 1.0 { *args.get(1)? } else { *args.get(2)? }
        "and" => if *args.get(0)? == 1.0 && *args.get(1)? == 1.0 { 1.0 } else { 0.0 }
        "or" =>  if *args.get(0)? == 1.0 || *args.get(1)? == 1.0 { 1.0 } else { 0.0 }
        "not" => if *args.get(0)? == 1.0 { 0.0 } else { 1.0 }

        // Other user code
        _ => // ...
    })
};

So, personally, I have no more need in int and bool types in fasteval 🤔

@optozorax
Copy link
Author

Oh, there are also the && and || operators already in fasteval. Yes, this support is not needed, maybe add if function.

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

No branches or pull requests

1 participant