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

Add basic support for REAL using f32/f64 with JER/OER rules #406

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

kodprussiluskan
Copy link
Contributor

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.

Copy link
Collaborator

@XAMPPRocky XAMPPRocky left a 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.

Cargo.toml Show resolved Hide resolved
Comment on lines 19 to 22
fn to_f64(&self) -> f64;

/// Converts a `f64` into the real type.
fn from_f64(value: f64) -> Self;
Copy link
Collaborator

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.

Comment on lines 3 to 5
#[cfg(any(feature = "f32", feature = "f64"))]
pub trait RealType:
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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

Copy link
Contributor Author

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.

@kodprussiluskan kodprussiluskan force-pushed the basic-real-support branch 2 times, most recently from ddd785e to 76311b8 Compare January 9, 2025 13:47
@kodprussiluskan kodprussiluskan force-pushed the basic-real-support branch 3 times, most recently from e34dd53 to f291c8a Compare January 10, 2025 09:57
@XAMPPRocky
Copy link
Collaborator

Thank you for your PR, and congrats on your first contribution! 🎉

@XAMPPRocky XAMPPRocky merged commit 1d06569 into librasn:main Jan 13, 2025
65 checks passed
@github-actions github-actions bot mentioned this pull request Jan 13, 2025
@kodprussiluskan kodprussiluskan deleted the basic-real-support branch January 13, 2025 13:49
@github-actions github-actions bot mentioned this pull request Jan 25, 2025
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 this pull request may close these issues.

3 participants