ISibboI / evalexpr

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

Option to output floats instead of rounded integers #168

Open soupslurpr opened 6 months ago

soupslurpr commented 6 months ago

Hi, could there be an option to automatically convert integers to floats especially when it results in rounding? For example, doing 1/16 results in 0 but I expect 0.0625.

ISibboI commented 6 months ago

Hi, in the current state of the crate that is not planned. If we ever abstract out the concrete numeric types, then we can also have variants that behave like this.

On Mon, 20 May 2024, 7.32 soupslurpr, @.***> wrote:

Hi, could there be an option to automatically convert integers to floats especially when it results in rounding? For example, doing 1/16 results in 0 but I expect 0.0625.

— Reply to this email directly, view it on GitHub https://github.com/ISibboI/evalexpr/issues/168, or unsubscribe https://github.com/notifications/unsubscribe-auth/AASATXXJ2NVCA7ZUKLIDL7TZDF4GBAVCNFSM6AAAAABH7AHN2OVHI2DSMVQWIX3LMV43ASLTON2WKOZSGMYDKMBVGU4DKOA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

soupslurpr commented 6 months ago

Okay, for now to achieve this I just change one line in tree/mod.rs line 842 from

Token::Int(int) => Some(Node::new(Operator::value(Value::Int(int)))),

to

Token::Int(int) => Some(Node::new(Operator::value(Value::Float(int as f64)))),

and it seems to work fine.