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

strconv: Doubt about atof #32494

Closed
achun opened this issue Jun 8, 2019 · 3 comments
Closed

strconv: Doubt about atof #32494

achun opened this issue Jun 8, 2019 · 3 comments

Comments

@achun
Copy link

achun commented Jun 8, 2019

{"0x1ep-1", "15", nil},

The code

{"0x1ep-1", "15", nil}

Should be

{"0x1ep-1", "0.9375", nil}
@robpike
Copy link
Contributor

robpike commented Jun 8, 2019

No, in hexadecimal constants the exponent is still in decimal and is a power of two. Thus this example is 30/2 not 30/16. (Anyway 0.9375 is 15/16; not sure how you got that.)

Thus the example is correct.

@robpike robpike closed this as completed Jun 8, 2019
@robpike
Copy link
Contributor

robpike commented Jun 8, 2019

From the spec:
A hexadecimal floating-point literal consists of a 0x or 0X prefix, an integer part (hexadecimal digits), a radix point, a fractional part (hexadecimal digits), and an exponent part (p or P followed by an optional sign and decimal digits). One of the integer part or the fractional part may be elided; the radix point may be elided as well, but the exponent part is required. (This syntax matches the one given in IEEE 754-2008 §5.12.3.) An exponent value exp scales the mantissa (integer and fractional part) by 2exp.

@achun
Copy link
Author

achun commented Jun 8, 2019

Thank you robpike

@golang golang locked and limited conversation to collaborators Jun 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants