[go-nuts] Re: is -2147483648 the same as MinInt32
Thanks to all. I speak Linux and sadly Winders 10 these days. I do have a MacBookPro that I got for IOS development years ago, but its old and way too slow. My fundamental problem was a NaN. Added a check and all is fine. Thanks -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] go build *.exe file size seems much too large
On Sun, Apr 21, 2019 at 7:16 PM wrote: > > For this simple go code, the *.exe file size is 1800 KB ...why so large > compared to equivalent C-compiled code ?? > package main > import( "math"; "fmt" ) > func main() { > fmt.Printf("\n %8.3f", math.Sin(1.2) ) > } > Does the go generated *.exe file contain code only for math.Sin() or all the > functions that comprise "math" ? > > Obviously there much more in the go *.exe file because of "fmt", but the > basic question still is why is the go *.exe file so large ?? > In addition to Sin() and Printf() what else is contained in the go *.exe file > ?? In addition to what other people said, Go programs are statically linked by default, while C++ programs are dynamically linked by default. Try comparing the size of "cc -static". Go is still bigger, but not quite as much. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] is -2147483648 the same as MinInt32
On Sun, Apr 21, 2019 at 8:37 PM Pat Farrell wrote: > I have a logic error in my calculation. I am getting -2147483648 in an > int32 > This sure looks a lot like MinInt32, but I can't seem to be able to tell, > all my calculators want to blow up on -1 << 31 > > > I'm willing to bet that my value is +/- one from whatever MinInt32 is in > decimal form. > A 2s-complement 32-bit int by definition can represent the range [-2147483648, 2147483647]. The definition of MinInt32 as `-1 << 31` presumes a 2s-complement representation. Also, given your problem statement why didn't you just compare the value you're getting from your calculation for equality to MinInt32 to confirm they are equal? -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] is -2147483648 the same as MinInt32
wolfram alpha is a good place to do numbers: https://www.wolframalpha.com/input/?i=-1+%3C%3C+31 if you're on a mac, the calculator has a "programmer mode" which allows arbitrary manipulations of bits. On Sun, Apr 21, 2019 at 9:36 PM Pat Farrell wrote: > > I have a logic error in my calculation. I am getting -2147483648 in an int32 > This sure looks a lot like MinInt32, but I can't seem to be able to tell, all > my calculators want to blow up on -1 << 31 > > > I'm willing to bet that my value is +/- one from whatever MinInt32 is in > decimal form. > > Is this correct? > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] is -2147483648 the same as MinInt32
Use Ivy? On Sun, Apr 21, 2019, 8:36 PM Pat Farrell wrote: > I have a logic error in my calculation. I am getting -2147483648 in an > int32 > This sure looks a lot like MinInt32, but I can't seem to be able to tell, > all my calculators want to blow up on -1 << 31 > > > I'm willing to bet that my value is +/- one from whatever MinInt32 is in > decimal form. > > Is this correct? > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] is -2147483648 the same as MinInt32
I have a logic error in my calculation. I am getting -2147483648 in an int32 This sure looks a lot like MinInt32, but I can't seem to be able to tell, all my calculators want to blow up on -1 << 31 I'm willing to bet that my value is +/- one from whatever MinInt32 is in decimal form. Is this correct? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] binary.Read cgo fields
On Sat, Apr 20, 2019 at 11:53 AM wrote: > > binary.Read can't set unexported fields, right? > But my structs are defined in C, and I can't make all C source code using > capital fields.. > What could I do? Read the fields separately. That is often a better idea in any case, as the result is more portable and avoids problems with structs that require padding between fields. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] go build *.exe file size seems much too large
the go runtime (bare, nothing else) is about 1.1MB now. the "fmt" package brings almost a MB of dependencies including 800 or so unicode-related functions (names/symbols), reflection, etc. the math package brings almost nothing: 11 symbols. -8< $ cat t.go package main func main() { } $ go build t.go && ls -lh t -rwxr-xr-x 1 a s 1.1M 21 Apr 20:35 t $ cat > t.go package main import "fmt" func main() { fmt.Println("test") } $ go build t.go && ls -lh t -rwxr-xr-x 1 a s 2.0M 21 Apr 20:36 t $ cat > t.go package main import ("fmt"; "math") func main() { fmt.Printf("\n %8.3f", math.Sin(1.2) ) } $ go build t.go && ls -lh t -rwxr-xr-x 1 a s 2.0M 21 Apr 20:38 t >8-- -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] go build *.exe file size seems much too large
It contains the Go runtime - memory manager, goroutine scheduler, all that. -- Marcin On Sun, Apr 21, 2019 at 7:16 PM wrote: > For this simple go code, the *.exe file size is 1800 KB ...why so large > compared to equivalent C-compiled code ?? > package main > import( "math"; "fmt" ) > func main() { > fmt.Printf("\n %8.3f", math.Sin(1.2) ) > } > Does the go generated *.exe file contain code only for math.Sin() or all > the functions that comprise "math" ? > > Obviously there much more in the go *.exe file because of "fmt", but the > basic question still is why is the go *.exe file so large ?? > In addition to Sin() and Printf() what else is contained in the go *.exe > file ?? > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] go build *.exe file size seems much too large
For this simple go code, the *.exe file size is 1800 KB ...why so large compared to equivalent C-compiled code ?? package main import( "math"; "fmt" ) func main() { fmt.Printf("\n %8.3f", math.Sin(1.2) ) } Does the go generated *.exe file contain code only for math.Sin() or all the functions that comprise "math" ? Obviously there much more in the go *.exe file because of "fmt", but the basic question still is why is the go *.exe file so large ?? In addition to Sin() and Printf() what else is contained in the go *.exe file ?? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] go execution speed for float64 based calculations vs float32
At least on intel, float64 should be faster than float32 since all math is done on the fpu in 64 bits, so it needs to be converted, but the memory bus also comes into play. I would doubt it. Float32 is designed for size not performance. > On Apr 21, 2019, at 8:55 PM, lgod...@gmail.com wrote: > > ?? On 64-bit CPUs does anyone have any experience comparing the run-time > speed of float64 based calculations vs float32 ? > > Some of my C-code when translated to Go-code seems to run noticeably slower, > so I'm wondering if I can speed things up by converting float vars to float32 > vs float64 > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] go execution speed for float64 based calculations vs float32
?? On 64-bit CPUs does anyone have any experience comparing the run-time speed of float64 based calculations vs float32 ? Some of my C-code when translated to Go-code seems to run noticeably slower, so I'm wondering if I can speed things up by converting float vars to float32 vs float64 -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Go+ replacement
This is unfortunate. It was less like that in the past. On Sun, 2019-04-21 at 18:02 -0700, icod.d...@gmail.com wrote: > Nuts is more of a "help I have a problem" thing. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: floating point question
I think michael Jones ' explanation is correct...when we x : =1.3 Go translates this to a binary representation of 1.3 that is a very close approximation to decimal 1.3 so when you do fmt.Printf( "\n %v ", x) you get the the binary version of x translated back to decimal, which will not be exactly 1.3 x=1.3(decimal) is NOT== 1.3(binary) exactly but will be very close approximation to it So to check floating point numbers for equaliy don't use if a== 1.4 {.} instead use if math.Abs(x-1.4) < 1.0e-8 {... } Whether you use 1.0e-8 or something some other value depends on your choice of 'how close to 1.4' would you consider ' is good enough' for the code you are working with On Monday, April 15, 2019 at 5:18:51 AM UTC-4, Miki Tebeka wrote: > > Hi, > > Can anyone explain the below? > (When printing out b with %.20f it prints 1.20996447) > > Thanks > > package main > > import "fmt" > > func main() { > a, b := 1.1*1.1, 1.21 > fmt.Println(a == b) // true > fmt.Println(1.1*1.1 == 1.21) // false > } > > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Does fmt.Fprint use WriteString ?
Hi gophers! Just wondering if in a Handler I should (w is the http.ResponseWriter): fmt.Fprint(w, "Hello world") or is it better to io.WriteString(w, "Hello world") or is it the same if fmt.Fprint already uses WriteString internally? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Go+ replacement
I don't know about you but for me, even if there wasn't so much going on, Google+ and the Go+ community was a source of info. Reddit is reddit, this whatever it is, is what it is, mewe can't replace G+. Facebook just isn't the crowd. Xing and the like just aren't made to handle the task of staying informed and people presenting their work. An essential source of information has disappeared. What is there to replace it? People would post links to youtube videos there, some were quite interesting and some were fresh from the horses mouth about whatever conferences or happenings. It's all gone now. Nuts is more of a "help I have a problem" thing. I know, Google+ had its own issues, the biggest was them forcing changes onto their users no one wanted. As a result most people stopped using it and in the end it disappeared. G+ did fill a nieche, that of the enterpreteur who also wanted to be entertained and catch news, stay up to date. I know this post is kind of pointless, since it won't change what is. But maybe something exists that I'm unaware of -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Mutual tls example
Thank you, may be i find mode detailed example https://diogomonica.com/2017/01/11/hitless-tls-certificate-rotation-in-go/amp/ вс, 21 апр. 2019 г. в 15:22, Aldrin Leal : > > I did a while ago, but I can't share a sample. But you can build one, > provided that: > > 1. build your server as such (note the ClientAuth - thats where magic > happens): > > ... > rootCAs, _ := x509.SystemCertPool() > > if nil == rootCAs { > rootCAs = x509.NewCertPool() > } > > cfg := { > MinVersion: tls.VersionSSL30, > /* > CurvePreferences: > []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256}, > PreferServerCipherSuites: true, > CipherSuites: []uint16{ > tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, > tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, > tls.TLS_RSA_WITH_AES_256_GCM_SHA384, > tls.TLS_RSA_WITH_AES_256_CBC_SHA, > }, > */ > ClientAuth: tls.VerifyClientCertIfGiven, > RootCAs:rootCAs, > } > > cert, err := tls.LoadX509KeyPair(*publicCertificate, *privateKey) > > ... > > > > srv := { > Addr: ":8043", > Handler: > handlers.RecoveryHandler(handlers.PrintRecoveryStack(true))(r), > TLSConfig:cfg, > TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, > http.Handler), 0), > } > > log.Fatal(srv.ListenAndServeTLS(*publicCertificate, *privateKey)) > > > 2. Look into http.Request, under TLS.PeerCertificates array > -- > -- Aldrin Leal, / https://ingenieux.io/about/ > > > On Sun, Apr 21, 2019 at 7:09 AM Vasiliy Tolstov wrote: >> >> Hi, I'm try to find mutual tls example in go, but can't find simple example >> that uses crypto/tls. I need server that for some http handler for user >> request with token returns tls cert for communication, and client that uses >> this cert to communication after it returned from request. Ideally with >> ability to rotate keys on client before previous expired. >> Does anybody knows it? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts+unsubscr...@googlegroups.com. >> For more options, visit https://groups.google.com/d/optout. -- Vasiliy Tolstov, e-mail: v.tols...@selfip.ru -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] fmt.Fprint or io.WriteString for http.ResponseWriter write?
When you check out the source code both, fmt.Fprint and io.WriteString, need a writer as the first argument. Writer is an interface type which provides an Write method. And thats exactly what that functions are calling.. the Write method of your provided w (which is http.ResponseWriter in your case). The difference is that fmt.Fprint is formatting the arguments provided first in a buffer before calling w.Write. And io.WriteString is checking if w provides the StringWriter interface and calls that instead. https://golang.org/src/fmt/print.go?s=6466:6527#L221 https://golang.org/src/io/io.go?s=10163:10218#L279 But to answer your question. In your simple case I would use io.WriteString. If you have more arguments than you could only use fmt.Fprint or you prepare your string by yourself before calling io.WriteString. Hope that helps (; Christian Sent from my iPhone > On 21. Apr 2019, at 15:59, José Colón wrote: > > Hi gophers! Is it better to (w is an http.ResponseWriter) > > fmt.Fprint(w, "Hello world") > > > or to > > io.WriteString(w, "Hello world") > > > or doesfmt.Fprint use io.WriteString behind the scenes, and thus they are > equivalent? > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: Does anyone know how to implement dynamic two-dimensional arrays ??
Burak Marcin and Miki : Many thanks, my problem is solved thanks to your comments On Sunday, April 21, 2019 at 1:10:40 AM UTC-4, lgo...@gmail.com wrote: > > Here's the snippet I'm trying to run > > package main > import ( "fmt" ) > > func main() { > Af(5) > } > > func Af ( N int) { > > //var M = new([N][N]uint16) !compiler error > //var M = make([N][N]uint16)!compiler error > > //var M = make([][]uint16, N*N) ## run-time error > > // run-time error > M := make( [][]uint16, N*N,N*N) > for y:=0; y< N; y++ { > for x :=0; x< N; x++ { >M[y][x] = uint16(100*y +x) > } } > > for y :=0; y< N; y++ { > fmt.Printf("\n y= %3d", y ) > for x :=0; x< N; x++ { >fmt.Printf(" %3d ", M[x][y] ) > } } > fmt.Printf("\n>>" ) > } > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] fmt.Fprint or io.WriteString for http.ResponseWriter write?
Hi gophers! Is it better to (w is an http.ResponseWriter) fmt.Fprint(w, "Hello world") or to io.WriteString(w, "Hello world") or doesfmt.Fprint use io.WriteString behind the scenes, and thus they are equivalent? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Mutual tls example
I did a while ago, but I can't share a sample. But you can build one, provided that: 1. build your server as such (note the ClientAuth - thats where magic happens): ... rootCAs, _ := x509.SystemCertPool() if nil == rootCAs { rootCAs = x509.NewCertPool() } cfg := { MinVersion: tls.VersionSSL30, /* CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256}, PreferServerCipherSuites: true, CipherSuites: []uint16{ tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, tls.TLS_RSA_WITH_AES_256_GCM_SHA384, tls.TLS_RSA_WITH_AES_256_CBC_SHA, }, */ ClientAuth: tls.VerifyClientCertIfGiven, RootCAs:rootCAs, } cert, err := tls.LoadX509KeyPair(*publicCertificate, *privateKey) ... srv := { Addr: ":8043", Handler: handlers.RecoveryHandler(handlers.PrintRecoveryStack(true))(r), TLSConfig:cfg, TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler), 0), } log.Fatal(srv.ListenAndServeTLS(*publicCertificate, *privateKey)) 2. Look into http.Request, under TLS.PeerCertificates array -- -- Aldrin Leal, / https://ingenieux.io/about/ On Sun, Apr 21, 2019 at 7:09 AM Vasiliy Tolstov wrote: > Hi, I'm try to find mutual tls example in go, but can't find simple > example that uses crypto/tls. I need server that for some http handler for > user request with token returns tls cert for communication, and client that > uses this cert to communication after it returned from request. Ideally > with ability to rotate keys on client before previous expired. > Does anybody knows it? > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Mutual tls example
Hi, I'm try to find mutual tls example in go, but can't find simple example that uses crypto/tls. I need server that for some http handler for user request with token returns tls cert for communication, and client that uses this cert to communication after it returned from request. Ideally with ability to rotate keys on client before previous expired. Does anybody knows it? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: Does anyone know how to implement dynamic two-dimensional arrays ??
Apart from writing your own, you might want to take a look at gonum - https://godoc.org/gonum.org/v1/gonum/mat On Sunday, April 21, 2019 at 8:10:40 AM UTC+3, lgo...@gmail.com wrote: > > Here's the snippet I'm trying to run > > package main > import ( "fmt" ) > > func main() { > Af(5) > } > > func Af ( N int) { > > //var M = new([N][N]uint16) !compiler error > //var M = make([N][N]uint16)!compiler error > > //var M = make([][]uint16, N*N) ## run-time error > > // run-time error > M := make( [][]uint16, N*N,N*N) > for y:=0; y< N; y++ { > for x :=0; x< N; x++ { >M[y][x] = uint16(100*y +x) > } } > > for y :=0; y< N; y++ { > fmt.Printf("\n y= %3d", y ) > for x :=0; x< N; x++ { >fmt.Printf(" %3d ", M[x][y] ) > } } > fmt.Printf("\n>>" ) > } > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.