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

proposal: Go 2: Add a Decimal Floating Point builtin type #26699

Closed
deanveloper opened this issue Jul 30, 2018 · 2 comments
Closed

proposal: Go 2: Add a Decimal Floating Point builtin type #26699

deanveloper opened this issue Jul 30, 2018 · 2 comments

Comments

@deanveloper
Copy link

deanveloper commented Jul 30, 2018

Quick disclaimer about this - I know a lot of people see floating-point-decimal numbers as a solution to having a "single, unified number type". This is not the goal in this case.

From here on out I will refer to the new builtin type as dec (although an implementation would most likely be dec64, decimal64, or similar).

People use decimal

One of the main reasons that Go would benefit from a dec type is that Go handles user-input. Decimal numbers are the notation that nearly all humans around the world naturally use, and converting decimal<->binary reals in some instances is a bit lossy to say the least. It prevents programmers from being able to handle tasks that should be simple.

Go should be fun and readable

Go is intended to be a programming language that's fun and easy to read. The current solution to use decimal numbers is the math/big.Rat structure, but the code is often hard to read since it does not use simple operators, but instead method wrappers. (going back to the classic .1 + .2 example)

Predictability and intuitiveness

dec of course isn't perfect. It's lossy too, but in more predictable ways. It is much more intuitive for a computer to think that 1.0 / 3.0 + 1.0 / 3.0 + 1.0 / 3.0 != 1.0 (as it would be .9999...) than it is for the common problem of .1 + .2 != .3. A solution to this would be a rat type, although the dec format is already standardized by IEEE.

A big issue with dec

Really the only issue I see with dec is that it offers multiple solutions to the real-number problem. One of my favorite parts about Go is that there are very few ways to do the same thing, making people who use the language think similarly and write similar code. Adding dec to the language would offer multiple ways to represent real numbers, which, in my opinion, is a bad thing to have. It would also add a lot of bloat to things like math which would need to add additional functions for new dec types.

All in all, I think Go would greatly benefit from a dec number type. It of course should NOT be the "universal number type", or replace binary floats (which have hardware to make them much faster), but it would make the experience of working with real numbers MUCH easier for programmers.

@gopherbot gopherbot added this to the Proposal milestone Jul 30, 2018
@kardianos
Copy link
Contributor

Is this a duplicate of #19787 or is there something that makes it different then existing issues?

@deanveloper
Copy link
Author

deanveloper commented Jul 30, 2018

I could've sworn I had looked to see if it was already made, my bad. I'll close and vote that one up.

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