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

Cleanup decimal64const.go #51

Open
MichaelDao opened this issue Jun 11, 2019 · 0 comments
Open

Cleanup decimal64const.go #51

MichaelDao opened this issue Jun 11, 2019 · 0 comments

Comments

@MichaelDao
Copy link
Contributor

Let's clean this up.

  1. Use consistent prefixes.
  2. Suffix everything with 64.
  3. Show the math behind the values.

Thus:

const (
	decDigits64  = 16
	expBits64    = 10
	expRange64   = 3 << (expBits - 2)
	symmMaxExp64 = expRange64 / 2
	symmMinExp64 = 1 - symmMaxExp64
	maxExp64     = symmMaxExp64 - (decDigits64 - 1)
	minExp64     = symmMinExp64 - (decDigits64 - 1)
)

We end up with symm(Max|Min)Exp64 = 384|-383 and (max|min)Exp64 = 369|-398.

The decimal128 group can then be written in exactly the same form, with the only changes being to the first two constants:

	decDigits128  = 34
	expBits128    = 14

It could even be extended to decimal32, in the event that we ever wanted to implement it:

	decDigits32  = 7
	expBits32    = 8

Technically, we could even derive decDigits(32|64|128):

	decDigits64  = (64 - expBits64) * 3 / 10

64 - expBits64 is the number of bits of precision available for the significand and 3/10 is close enough to log(2)/log(10) to convert bits to digits for the given values of expBits(32|64|128). But I think this a bit too abstruse for the reader.

https://play.golang.org/p/X-WNwWgkcht

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

No branches or pull requests

1 participant