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 floating-point internal bit representation to TypeInfo #1139

Closed
wants to merge 1 commit into from

Conversation

tiehuis
Copy link
Member

@tiehuis tiehuis commented Jun 20, 2018

This makes writing floating-point generic code easier if it works with the internal bit representation.

Note that 80-bit extended precision floats may have a slightly different internal representation to all other types and according to IEEE this may be implementation defined. It currently is set to the most likely representation. We typically don't accept long doubles in the current math functions so can see how this plays out in practice, special casing if needed.

https://en.wikipedia.org/wiki/Extended_precision#x86_extended_precision_format

@tiehuis
Copy link
Member Author

tiehuis commented Jun 20, 2018

So I was playing around with this a bit and in terms of usage, it may be slightly nicer to instead expose a userland function in std which returns a comptime int. The bitwise shifts to extract the mantissa/exponent need to otherwise perform an explicit cast to a Log2Int of the suitable size anyway.

Thoughts on this approach vs. the current?

@BraedonWooding
Copy link
Contributor

BraedonWooding commented Jun 20, 2018

An important thing also is the bias (often represented as a negative number despite being 'positive'). So that probably needs to be added. I was using that today when implementing atof.

@tiehuis
Copy link
Member Author

tiehuis commented Jun 20, 2018

The bias can be computed directly from the exponent bits for any floating point type via (1 << (exponent_bits - 1)) - 1 so isn't essential.

@BraedonWooding
Copy link
Contributor

Fair enough

@andrewrk
Copy link
Member

If @reify becomes a thing, it would make sense for these values to be elsewhere - having to specify them would be redundant since they can be determined based on the bit count.

I would lean towards the userland std lib function approach.

@tiehuis
Copy link
Member Author

tiehuis commented Jun 20, 2018

@andrewrk

Alright, sounds good. Will open a new PR at some stage with equivalent functions. Will modify some of the existing math functions while I'm at it for comparison.

@tiehuis tiehuis closed this Jun 20, 2018
@tiehuis tiehuis deleted the float-typeinfo branch June 20, 2018 11:23
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.

None yet

4 participants