ISibboI / evalexpr

A powerful expression evaluation crate 🦀.
GNU Affero General Public License v3.0
325 stars 54 forks source link

Add math consts context #80

Closed olback closed 3 years ago

ISibboI commented 3 years ago

Hi, and thank you very much for this pull request as well.

This looks also very nice.

chaosprint commented 1 year ago

Hi,

I tried to run eval_float_with_context_mut("PI", &mut context) but get an Err value: VariableIdentifierNotFound("PI")'.

The same goes for eval_float_with_context_mut("f64::consts::PI", &mut context).

What's the correct way to use the consts?


I see. I need to do this first:

        let context = math_consts_context!(
            PI
        ).unwrap();

But shouldn't this be the default for HashMapContext::new()?

ISibboI commented 1 year ago

You need to construct your context with the macro added by this pull request.

On Tue, Jan 10, 2023 at 10:28 AM Qichao Lan @.***> wrote:

Hi,

I tried to run eval_float_with_context_mut("PI", &mut context) but get an Err value: VariableIdentifierNotFound("PI")'.

The same goes for eval_float_with_context_mut("f64::consts::PI", &mut context).

What's the correct way to use the consts?

— Reply to this email directly, view it on GitHub https://github.com/ISibboI/evalexpr/pull/80#issuecomment-1376895825, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASATXW6KC55AR2JJPRKVIDWRUMRXANCNFSM45ZEULKA . You are receiving this because you modified the open/close state.Message ID: @.***>

olback commented 1 year ago

One could argue that HashMapContext::default() should have some sane defaults, but HashMapContext::new() should definitely create an empty context.