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

[go-nuts] Re: What is the relationship between go community and goproxy.io

2022-10-10 Thread tapi...@gmail.com
On Monday, October 10, 2022 at 3:11:06 PM UTC+8 Brian Candler wrote: > > By the go module cache system design, if you trust the server set in > your GOSUMDB env var, > > which is defaulted to sum.golang.org, then it is not a matter whatever > proxy server your are using. > > From the point of

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] behavior of %f

2022-10-10 Thread robert engels
He was using that as an example to show that the value contained in the float is not 1, but less than 1, even though the print shows it as 1. > On Oct 10, 2022, at 8:07 PM, Bakul Shah wrote: > > On Oct 10, 2022, at 5:40 PM, Dante Castagnoli > wrote: >> >> Also, if you were to take an int(f),

Re: [go-nuts] behavior of %f

2022-10-10 Thread Bakul Shah
On Oct 10, 2022, at 5:40 PM, Dante Castagnoli wrote: > > Also, if you were to take an int(f), you will note that it returns "0", and > not "1". %0.3f does *rounding*, while int(f) does *truncation*. 1.0 is closer to 0.... than 0.999 is to 0.... -- You received this message because yo

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] behavior of %f

2022-10-10 Thread robert engels
I will add that this is why most financial applications using “fixed place” or “integer math” libraries - to have control over these sorts of issues. An example is robaho/fixed > On Oct 10, 2022, at 6:35 PM, Dante Castagnoli > wrote: > > Thanks, Rob, > > As t

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

Re: [go-nuts] get function body comments using ast

2022-10-10 Thread 'wagner riffel' via golang-nuts
On 10/9/22 11:09, Dmitry Belyaev wrote: For a function like below I'd get only *example // doc comment*, // doc comment func example() {   // body comment   < looking to extract this comment } but I am looking also to extract *// body comment*. Please advise on how to extract function nam

[go-nuts] Re: behavior of %f

2022-10-10 Thread Dante Castagnoli
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 out what was going on, is all. As the behavior ma

[go-nuts] I need help with this project

2022-10-10 Thread Kazuya Nomura
Hello, The project is about building a decentralized P2P network (platform) based on the IPFS or libp2p network framework. The project has 7 main phases: 1) Build a P2P network, where each node/peer participating in this network must be capable of discovering, routing, messaging, file sharing, an

[go-nuts] Re: golang.org/x/exp/jsonrpc2 bugs

2022-10-10 Thread Maxime Soulé
Hi Jason, I didn't realized this repo followed the same rules as golang/go. Thank for your help and sorry for the noise. Regards, Max. Le lundi 10 octobre 2022 à 18:53:43 UTC+2, Jason Phillips a écrit : > Are these existing known bugs or did you open a ticket on the Go bug > tracker? If ther

Re: [go-nuts] Internationalized webpage depending on the user's web browser locale

2022-10-10 Thread 'Sean Liao' via golang-nuts
.Lang comes from something gitea provided to the template, it's not an intrinsic part of go - sean On Mon, Oct 10, 2022, 19:48 Christoph wrote: > Hello, > > I am running a git-server, powered by gitea, an open-source git server > project written in Go. In gitea, it is possible to customize the

[go-nuts] Write heap dump in a forked process - could that be even possible?

2022-10-10 Thread Konstantin Khomoutov
More than once at my $dayjob we experienced the need to grab the heap dump or a running process implementing some critical functionality. The problem is that saving of the dump file requires freezing of the process, and if its memory consumption is relatively high (in our case it clocked around 50

[go-nuts] Re: behavior of %f

2022-10-10 Thread Brian Candler
Whilst Go handles constants with arbitrary precision AFAIK, precision is lost once values are assigned to a float64 variable (or passed as an argument to a function). There are only 53 bits of precision in the "mantissa". For more info, you might find this helpful: https://0.30004.

[go-nuts] Re: golang.org/x/exp/jsonrpc2 bugs

2022-10-10 Thread Jason Phillips
Are these existing known bugs or did you open a ticket on the Go bug tracker? If there are already tickets for these known bugs, you should mention the ticket number in your code review. If there aren't tickets, you should probably start by opening a ticket and then linking to your changes. As

[go-nuts] behavior of %f

2022-10-10 Thread Dante Castagnoli
Hi, I'm wondering what folks think about the behavior of %f and precision. The go fmt documentation states: > For floating-point values, width sets the minimum width of the field and precision sets the number of places after the decimal, What I discovered is there is rounding going on in %f as

[go-nuts] Internationalized webpage depending on the user's web browser locale

2022-10-10 Thread Christoph
Hello, I am running a git-server, powered by gitea, an open-source git server project written in Go. In gitea, it is possible to customize the home page, what I did. My customized home page, among other things, contains: {{if eq .Lang "de-DE"}} Willkommen auf dem Git-Server der Fakultät

[go-nuts] golang.org/x/exp/jsonrpc2 bugs

2022-10-10 Thread Maxime Soulé
Hi Gophers! Does anyone know if the jsonrpc2 sub-directory of golang.org/x/exp is still maintained? If yes, perhaps could you point me to the right person? as there are 2 pending bug fixes that do not seem to arouse somebody curiosity :) https://go-review.googlesource.com/c/exp/+/412334 https:

Re: [go-nuts] Detecting JSON changes

2022-10-10 Thread Shulhan
On Mon, 10 Oct 2022 07:50:20 -0700 (PDT) Slawomir Pryczek wrote: > Hi Guys, > I have 2 json files, A, B. Now i want to detect changes on the root > level. > > File A: {"a":{"b":1, "c":2}, "x":false, ... } > File B: {"a":{"b":1, "c":2}, "x":true, ... } > > I want to be able to see that x is di

Re: [go-nuts] Detecting JSON changes

2022-10-10 Thread burak serdar
On Mon, Oct 10, 2022 at 8:50 AM Slawomir Pryczek wrote: > Hi Guys, > I have 2 json files, A, B. Now i want to detect changes on the root level. > > File A: {"a":{"b":1, "c":2}, "x":false, ... } > File B: {"a":{"b":1, "c":2}, "x":true, ... } > > I want to be able to see that x is different betwe

[go-nuts] Detecting JSON changes

2022-10-10 Thread Slawomir Pryczek
Hi Guys, I have 2 json files, A, B. Now i want to detect changes on the root level. File A: {"a":{"b":1, "c":2}, "x":false, ... } File B: {"a":{"b":1, "c":2}, "x":true, ... } I want to be able to see that x is different between A and B and a stayed the same. What would be the easiest approach?

[go-nuts] Re: Issue with go-git API

2022-10-10 Thread Brian Candler
Basically, every program now needs a "go.mod" file. Even a "hello world" program should be made like this: mkdir hello cd hello go mod init example.com/hello# this creates "go.mod" vi hello.go # create your program here go run . Whilst it still does work to say "go run hello.go" for a sim

Re: [go-nuts] Issue with go-git API

2022-10-10 Thread Martin Schnabel
Hi PK, most of the time examples are single file programs to be used with go run. if you are inside the module root that covers all the dependencies (or decend into the relevant example folder) you can use `go run main.go` to run the example file. I just tired it with the same repository and

[go-nuts] Re: Issue with go-git API

2022-10-10 Thread peterGo
Follow the instructions in the error messages: see `go help modules`. On Monday, October 10, 2022 at 1:35:38 AM UTC-4 princ...@gmail.com wrote: > I am trying to use this git api(*https://github.com/go-git/go-git > *), but before that I tried to run the > provid

[go-nuts] Does Go team have a preference on codegen over reflect style?

2022-10-10 Thread ag9920
There're many reflect-based mock and inject tools, and they are quite helpful. But I noticed that the famous official mock tool mockgen and dependency injection tool wire both follow codegen style. So just out of curiosity, I want to know the underlying reason for that, is codegen better than

[go-nuts] Re: Practical use cases of recover in golang

2022-10-10 Thread Vladimir Varankin
One particular example is if you use std's net/http server, you (indirectly) use recover. The std's documentation for the Handler interface has a section, where they outline how the server recovers from a panic, that fired in the context of a request https://pkg.go.dev/net/http#Handler On Sunda

Re: [go-nuts] Practical use cases of recover in golang

2022-10-10 Thread Brian Candler
On Monday, 10 October 2022 at 06:21:48 UTC+1 Henry wrote: > You may want to make your app more robust by handling panic in the topmost > layer of your application. With many people working on the code and various > external dependencies, it is often impractical to ensure none of the code > pani

[go-nuts] Re: What is the relationship between go community and goproxy.io

2022-10-10 Thread Brian Candler
> By the go module cache system design, if you trust the server set in your GOSUMDB env var, > which is defaulted to sum.golang.org, then it is not a matter whatever proxy server your are using. >From the point of view of downloaded package integrity, yes. But there are other things an untrustw