This repository was archived by the owner on Feb 1, 2020. It is now read-only.
K-buitin Floats do not provide any hooks to convert a specific bit pattern into a single precision or double precision floating point value.#2383
Open
sdasgup3 wants to merge 10 commits intokframework:masterfrom
sdasgup3:machineFloatSupport
Open
K-buitin Floats do not provide any hooks to convert a specific bit pattern into a single precision or double precision floating point value.#2383sdasgup3 wants to merge 10 commits intokframework:masterfrom sdasgup3:machineFloatSupport
sdasgup3 wants to merge 10 commits intokframework:masterfrom
sdasgup3:machineFloatSupport
Conversation
…ttern into a single precision or double precision floating point value.
Requirement: We need the ability to do the conversion as shown in examples:
Example 1:
bit-vector: 32' 01000001 01000110 00000000 00000000 === MInt(32, 1095106560)
convert to or from
Float(single precision): 12.375f.
Example 2:
bit-vector: 64' 0b0100000000101000110000000000000000000000000000000000000000000000 === MInt(64, 4623156123728347136)
convert to or from
Float(single precision): 12.375d.
Commit:
Provides two following two hooks:
1. float2mint(Float F, Int W): Converts a float point value F(single or double precision) to a BitVector or MInt of bitwidth W.
2. mint2float(MInt MI, Int Precision, Int Exponent): Converts a Bitvector or MInt to an single or double precision float point value.
The hooks are tested extensively using corner cases.
Note: The available hooks like float2Int or int2Float converts between the float and its integer equivalent and hence not suitable.
From example 2, int2Float(4623156123728347136) gives 4.623156123728347136 e+18
Some peculiarities of exiting mpfr library support:
1. While creating the BigFloat using BigFLoat constrcutor, we need to pass the unbiased exponent (mint(e1...e8) - 127) as the callee expects that. This is more evident from
https://github.com/kframework/mpfr-java/blob/a24d33c7589e285e840eaaba74368581dc15ebb3/src/main/java/org/kframework/mpfr/BigFloat.java#L357
where exponent is compared with mc.minExponent(-126) and mc.MaxExponent(+127).
2. For zero, BigFloat constructor expects -127 as opposed to -126 (a special exponent used for +/- zero). Inside the constructor, its converted back to 126. This is used to easily distinguish =/- zero and sub normals value from others.
https://github.com/kframework/mpfr-java/blob/a24d33c7589e285e840eaaba74368581dc15ebb3/src/main/java/org/kframework/mpfr/BigFloat.java#L364
Contributor
|
Can one of the admins verify this patch? |
Contributor
|
Jenkins: ok to test |
…aviour is to warn with an exception thrown, but the mvn -e clean verify make the wanr an error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirement
We need the ability to do the conversion as shown in examples:
Commit:
Note
The available hooks like float2Int or int2Float converts between the float and its integer equivalent and hence not suitable.
From example 2, int2Float(4623156123728347136) gives 4.623156123728347136 e+18
Some peculiarities of exiting mpfr library support:
While creating the BigFloat using BigFLoat constrcutor, we need to pass the unbiased exponent (mint(e1...e8) - 127) as the callee expects that. This is more evident from
https://github.com/kframework/mpfr-java/blob/a24d33c7589e285e840eaaba74368581dc15ebb3/src/main/java/org/kframework/mpfr/BigFloat.java#L357
where exponent is compared with mc.minExponent(-126) and mc.MaxExponent(+127).
For zero, BigFloat constructor expects -127 as opposed to -126 (a special exponent used for +/- zero). Inside the constructor, its converted back to 126. This is used to easily distinguish =/- zero and sub normals value from others.
https://github.com/kframework/mpfr-java/blob/a24d33c7589e285e840eaaba74368581dc15ebb3/src/main/java/org/kframework/mpfr/BigFloat.java#L364
Please accept the request if it seems suitable to the k-developers.