Re: [go-nuts] Re: behavior of %f

2022-10-11 Thread Marvin Renich
* Dante Castagnoli [221010 18:01]: > Thanks! > > It's not lost, though. It shows up with the %g form. > > Knowing about %g, my issue is not extant, but others might hit it. I'm > relatively new to floating point issues, and I saw numbers showing up as > integers, and it took a while to sort

Re: [go-nuts] Re: behavior of %f

2022-10-10 Thread Patrick Smith
On Mon, Oct 10, 2022 at 6:10 PM Patrick Smith wrote: > %g differs from %f when printing large or small values. > https://go.dev/play/p/lxj9fn19kOO > For the sake of completeness, I should add that they can also differ for "normal" sized values: https://go.dev/play/p/xiFwOrK8Tv6 With %f, one spe

Re: [go-nuts] Re: behavior of %f

2022-10-10 Thread Patrick Smith
This program (https://go.dev/play/p/w-QE790dGcs) func main() { f := 0.999 fmt.Printf("%0.2f %0.3f %0.4f\n", f, f, f) fmt.Println(f) fmt.Printf("%0.64f\n", f) } prints 1.00 0.999 0.9990 0.999 0.99899911182158029987476766109466552734375000 The last line prints

Re: [go-nuts] Re: behavior of %f

2022-10-10 Thread Dante Castagnoli
Sean, Your comment is not correct. You can take the original program I wrote and increase the digits and will notice they are printed as they are meant to be. Also, if you were to take an int(f), you will note that it returns "0", and not "1". Sorry! Incorrect information ought to be corrected

Re: [go-nuts] Re: behavior of %f

2022-10-10 Thread 'Sean Liao' via golang-nuts
> leaving one with the impression those digits will be as they are in the float, and not rounded. This is a fundamental misunderstanding of what a float is. The rounding happens the moment a value is stored in a float. The printed value is exactly what is stored. - sean -- You received this mes

Re: [go-nuts] Re: behavior of %f

2022-10-10 Thread Dante Castagnoli
Thanks, Rob, As the behavior is as in "C", the behavior is as it should be. I also understand that "1" is a closer representation than 0. should the number be 0.9, though it's a choice as it diverges from string-type formats. Regardless of whether the choice was right or wrong, it is imm

Re: [go-nuts] Re: behavior of %f

2022-10-10 Thread Rob Pike
This behavior is how floating-point math works, which is not best addressed in the documentation for the formatted I/O library. We see may comments from people new to floating point who argue that there are bugs in Go's arithmetic, but it's invariably a lack of familiarity with the—admittedly rathe