evalexpr icon indicating copy to clipboard operation
evalexpr copied to clipboard

Add features: `decimal_support`/`empty_is_null`

Open gaoqiangz opened this issue 2 years ago • 1 comments

This PR adds two features decimal_support and empty_is_null.

Feature decimal_support #115

The decimal_support feature enables support for Decimal float type calculation using the rust_decimal library. Note that due to limitations in the rust_decimal library, certain math calculations are not supported.,the following built-in functions are not available:

  • log
  • log2
  • exp2
  • acos
  • cosh
  • acosh
  • asin
  • sinh
  • asinh
  • atan
  • tanh
  • atanh
  • atan2
  • cbrt
  • hypot
  • is_nan
  • is_finite
  • is_infinite
  • is_normal

Feature empty_is_null

The empty_is_null feature ensures that calculations involving the Empty type behave similarly to Null, following the SQL Null standard (https://en.wikipedia.org/wiki/Null_(SQL)).

use evalexpr::*;

assert_eq!(eval("1 + 2 + ()"), Ok(Value::Empty)));
assert_eq!(eval("() * 2"), Ok(Value::Empty)));
assert_eq!(eval("2 / () "), Ok(Value::Empty)));
assert_eq!(eval("true && () "), Ok(Value::Empty)));
assert_eq!(eval("true || ()"), Ok(Value::Boolean(true))));
assert_eq!(eval("false || ()"), Ok(Value::Empty)));

gaoqiangz avatar Jul 09 '23 11:07 gaoqiangz

Thank you for the pull request. I agree that supporting rust_decimal would be great for this crate! However I have doubts about the maintainability of the changes made in this pull request, as they are introducing a vast number of conditional compilation. I have before planned to support custom numeric types in a different way via generics, but did not have time for that yet. Merging this pull request would not make it easier to make the numeric types generic, hence I am sorry but I have to reject this pull request.

ISibboI avatar Jul 12 '23 07:07 ISibboI