-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
REAL type support #145
Comments
@Nicceboy I like the approach of staying close to ASN1's understanding of the |
Bump I am working with ASN.1 records using the REAL type, which has some incompatibility with the compiler's assigning |
I like the idea of allowing the user to override the |
I think it would make sense in the compiler to check if the components when it is generating derives. If it checked it's components and subcomponents for any presence of REAL, then if none are found, add the Hash and Eq definitions. |
|
|
Sounds like worth writing down thoughts on at least. Would you care to open a follow up issue with your initial thoughts and we can discuss it further? |
I'm curious if there are plans to add REAL type support for PER/BER encodings. I noticed this issue was marked complete just a few days ago (and I realize there could likely still be work in the pipeline as a result of that), but I just wanted to check. |
"Plans" is a strong word 😄 They should support REAL but we should open new issues for those as the framework supports REAL types generally. If someone wants to contribute those implementations, PR are encouraged 😄 |
I was more likely seeking new opinions elsewhere since the current implementation was made by me 😄 |
What speaks against an implementation as you initially proposed?
I guess with |
Sorry, I was speaking about the |
Continuing from the issue #58 and writing some ideas
I also noticed that real type is missing, but it might not be actually that hard to add (while some codecs might be)!
In ASN.1, real type is often approximated and not precise. Usually a single or double-precision approximation has been used to limit the size in codecs. The X.680 definition itself does not set any limits, but for practical reasons codecs often do.
Usually the real is presented with integers. Instead of one integer, you have three integers.
Representing real type is like bit shifting, but instead moving the comma. The shifting changes the exponent relatively moving the comma, so in the end you have just integers.
Based on that, maybe the easiest approach would be to provide Real as Enum type with following options:
Internally
rasn
could contain thef64
conversion to ASN.1 Real value as three integers, possibly with sign. BER seems to use sign with unsigned integers when binary encoding.Mapping from
f64
type might be good enough for default, since it is sufficient for double-precision approximation.Any application which requires higher precision is more likely to use rations with integers anyway in current Rust.
To support very large numbers, BigInt could be used to present these three integers internally.
For larger values than
f64
, we could provide alternatively something likeReal_number::from_ints
function which takes three integers to construct the ASN.1 Real. BigInt as mantissa, u8 as base (2 or 10) and BigInt as exponent will already give us practically as much range as hardware is able to handle.Alternatively, BigUint as mantissa and additional sign parameter. For this we might need to study which (sign as mark with unsigned integer or signed integer) is more used in the codecs.
It is up to the user of
rasn
to calculate these three integers if they need higher accuracy thanf64
.Maybe this REAL type overall would be good to add at the same time when the possibly for optional BigInt usage is added and end user could configure to use primitive integers instead, if we want to consider the performance of REAL values as well.
It might also take time before we would have other than
f32
orf64
types.There is a recent RFC coming with additional float types: rust-lang/rfcs#3451
The text was updated successfully, but these errors were encountered: