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

Distinguish between Values containing integers and floats #576

Closed
evroon opened this issue Sep 6, 2024 · 1 comment · Fixed by #580
Closed

Distinguish between Values containing integers and floats #576

evroon opened this issue Sep 6, 2024 · 1 comment · Fixed by #580

Comments

@evroon
Copy link
Contributor

evroon commented Sep 6, 2024

Hi, I would like to be able to distinguish between a Value representing integers (ValueRepr::U64, ValueRepr::I64 etc.) and a Value representing a float (ValueRepr::F64).

Right now, there isn't a way to know whether a Value contains a float or int because

  • The ValueRepr (Value.0) is private
  • ValueKind considers ints and floats all to be a ValueKind::Number
  • Converting a Value doesn't reveal this information either, it just converts floats to ints and vice versa:
assert_eq!(Value::from(0.0).as_i64().unwrap(), 0);
assert_eq!(f64::try_from(Value::from(0)).unwrap(), 0.0);

This distinction can be quite useful if you want to format a value differently based on whether it's an int or float for example.

I'm happy to create a PR for this if that helps but I'm not sure what the best approach is.

@evroon
Copy link
Contributor Author

evroon commented Sep 24, 2024

Thanks a lot!

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 a pull request may close this issue.

1 participant