-
-
Notifications
You must be signed in to change notification settings - Fork 56
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
Add basic support for REAL using f32/f64 with JER/OER rules #406
Conversation
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.
Thank you for your PR! Overall I like this approach for starting out with implementing REAL, since it specifies the ideal interface, I have a couple of comments, but overall LGTM.
src/types/real.rs
Outdated
fn to_f64(&self) -> f64; | ||
|
||
/// Converts a `f64` into the real type. | ||
fn from_f64(value: f64) -> Self; |
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.
These should be TryInto
/TryFrom
equivalents meaning that it should allow for the possibility that it fails to convert.
src/types/real.rs
Outdated
#[cfg(any(feature = "f32", feature = "f64"))] | ||
pub trait RealType: |
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.
Similar to the question above, this trait should always be available even if those types aren't to allow people to use custom float types.
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.
See my comment about embedded targets, however, RealType might need some work anyway since you can have f32 support, but no hw support for 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.
Right but you could decode real types into non floating point types. I think we should remove the cfg flags for everything except the trait definitions for f32 and 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.
Updated, RealType is now always available, and only the actual implementations are guarded by the f32/f64 feature flags.
ddd785e
to
76311b8
Compare
e34dd53
to
f291c8a
Compare
f291c8a
to
9614352
Compare
Thank you for your PR, and congrats on your first contribution! 🎉 |
I think this is a compliant implementation of REAL, as long as you're fine with being constrained to 32/64-bit floats.
From what I can gather this is the first type that isn't supported for every codec so I added a generic error for the unsupported codecs. Unfortunately this means that you won't get an error until runtime.
I added f32/f64 feature flags so you don't have to use any of it if you don't want it.
Neither my rust nor my asn.1 is something to brag about, so if you want it done in another way just let me know.