Re: [go-nuts] Re: Are Go floats smarter?

2018-09-02 Thread Dan Kortschak
This is not much different. I is the same as const c = 0.3 - 0.1*3 func BenchmarkUntypedConstants(b *testing.B) { b.Log(0.3 - 0.1*3) for i := 0; i < b.N; i++ { z = c } } On Sun, 2018-09-02 at 20:25 -0700, José Colón wrote: > Yeah, after posting I realized that the compiler

Re: [go-nuts] Re: Are Go floats smarter?

2018-09-02 Thread José Colón
Yeah, after posting I realized that the compiler would probably be smart enough to optimize that out, so I changed them to: func BenchmarkUntypedConstants(b *testing.B) { var z float64 for i := 0; i < b.N; i++ { z = 0.3 - 0.1*3 } b.Log(z) } func BenchmarkDecimalPackage(b *testing.B) { var z

Re: [go-nuts] Re: Are Go floats smarter?

2018-09-02 Thread Dan Kortschak
This is not a benchmark of the untyped constant expression evaluation. The expression in the loop is performed once and thrown away *at compile time*. The benchmark here is really: func BenchmarkUntypedConstants(b *testing.B) { b.Log(0.3 - 0.1*3) for i := 0; i < b.N; i++ {     } } On

Re: [go-nuts] Re: Are Go floats smarter?

2018-09-02 Thread Wojciech S. Czarnecki
On Sun, 2 Sep 2018 15:54:08 -0700 (PDT) José Colón wrote: > if a package that could provide similar ease of use in performing > infinite precision calculations would be a good idea https://github.com/ericlagergren/decimal It does not fit into stdlibs imo. -- Wojciech S. Czarnecki << ^oo^

Re: [go-nuts] Re: Are Go floats smarter?

2018-09-02 Thread Michael Jones
for money there is a natural limit to the number of digits that are useful, with certain exceptions . add to this the number of digits of fractional

Re: [go-nuts] Re: Are Go floats smarter?

2018-08-31 Thread Michael Jones
yes. another way to say it is that money is best considered integral in terms of some chosen "minimum accounting unit" which in the case of USD might be a dollar, a cent (1/100 dollar), or a finer thing, such as 1/100 or 1/1000 of a cent. This allows crossfooting to work, balances to zero, and

Re: [go-nuts] Re: Are Go floats smarter?

2018-08-31 Thread Ken MacDonald
Financial applications are, indeed, typically written using some sort of integer representation; some that I've worked with require smaller than "penny" level representations, say, for commodity pricing. I have seen accounting done with floating point. It didn't end well. One of the problems is

Re: [go-nuts] Re: Are Go floats smarter?

2018-08-30 Thread Marvin Renich
* José Colón [180830 06:53]: > Very interesting. So would it be a good idea to use these types of untyped > constant calculations for financial applications, or instances where one > would use the math.big package? Not likely. You would have to know at compile time the exact values you wanted