-
Notifications
You must be signed in to change notification settings - Fork 209
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
implement f32 data type #1145
implement f32 data type #1145
Conversation
Pull Request Test Coverage Report for Build 4802818313
💛 - Coveralls |
I can't wait to see another data type being added to our project :) |
@panarch , can i add tests not related to the f32 type but to other types? |
Sure! but it would be good to make a separate PR, then I can do quick review and merge. |
Ok, I think so |
core/src/data/value/convert.rs
Outdated
Value::I32(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?, | ||
Value::I64(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Value::I32(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?, | |
Value::I64(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?, | |
Value::I32(value) => *value as f32, | |
Value::I64(value) => *value as f32, |
Could you please also change the f64 below? These types have a smaller range than f32.
core/src/data/value/convert.rs
Outdated
Value::U8(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?, | ||
Value::U16(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?, | ||
Value::U32(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?, | ||
Value::U64(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?, | ||
Value::U128(value) => value.to_f32().ok_or(ValueError::ImpossibleCast)?, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
core/src/data/value/convert.rs
Outdated
@@ -872,6 +944,8 @@ mod tests { | |||
test!(Value::U32(122), Ok(122)); | |||
test!(Value::U64(122), Ok(122)); | |||
test!(Value::U128(122), Ok(122)); | |||
test!(Value::F32(122.0_f32), Ok(122)); | |||
test!(Value::F64(122.9), Ok(122)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test!(Value::F64(122.9), Ok(122)); |
There is duplicate code below. Could you please remove it?
core/src/data/value/mod.rs
Outdated
(F64(a), _) => a.try_multiply(other), | ||
(Decimal(a), _) => a.try_multiply(other), | ||
(Interval(a), I8(b)) => Ok(Interval(*a * *b)), | ||
(Interval(a), I16(b)) => Ok(Interval(*a * *b)), | ||
(Interval(a), I32(b)) => Ok(Interval(*a * *b)), | ||
(Interval(a), I64(b)) => Ok(Interval(*a * *b)), | ||
(Interval(a), I128(b)) => Ok(Interval(*a * *b)), | ||
(Interval(a), F32(b)) => Ok(Interval(*a * (*b) as f64)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason for casting? I think performing the operation with multiplication in f32 would be desirable.
core/src/data/value/mod.rs
Outdated
@@ -478,6 +494,7 @@ impl Value { | |||
(Interval(a), U32(b)) => Ok(Interval(*a / *b)), | |||
(Interval(a), U64(b)) => Ok(Interval(*a / *b)), | |||
(Interval(a), U128(b)) => Ok(Interval(*a / *b)), | |||
(Interval(a), F32(b)) => Ok(Interval(*a / (*b as f64))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
test!(add F32(1.0_f32), F64(2.0) => F64(3.0)); | ||
test!(add F32(1.0_f32), I8(2) => F32(3.0_f32)); | ||
test!(add F32(1.0_f32), I32(2) => F32(3.0_f32)); | ||
test!(add F32(1.0_f32), I64(2) => F32(3.0_f32)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some data types are empty (there are also other places that need to be organized, so it requires a cleanup. The code for organizing other places might be better handled in a separate PR).
ex) U8, U16, ...
?
test!(subtract I8(3), F32(2.0_f32) => F32(1.0_f32)); | ||
test!(subtract I32(3), F32(2.0_f32) => F32(1.0_f32)); | ||
test!(subtract I64(3), F32(2.0_f32) => F32(1.0_f32)); | ||
test!(subtract I128(3), F32(2.0_f32) => F32(1.0_f32)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
test-suite/src/function/extract.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not related to this PR. Please submit it as a separate PR or open an issue for it.
assert_eq!(U32(9).sqrt(), Ok(F32(3.0_f32))); | ||
assert_eq!(U64(9).sqrt(), Ok(F32(3.0_f32))); | ||
assert_eq!(U128(9).sqrt(), Ok(F32(3.0_f32))); | ||
assert_eq!(F32(9.0_f32).sqrt(), Ok(F32(3.0_f32))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that there are no cases for (f64, f32)
and (f32, f64)
.
3d9504b
to
b94f3f5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks all nice!!
Just before the merge, could you add an integration test of float32
in test-suite?
ref.
https://github.com/gluesql/gluesql/tree/main/test-suite/src/data_type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks all great!!
Thanks a lot 👍
Implementation of f32 for issue #623