You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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 bedec64
,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 that1.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 arat
type, although thedec
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. Addingdec
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 likemath
which would need to add additional functions for newdec
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.The text was updated successfully, but these errors were encountered: