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

[go-nuts] Re: Is it possible and how to connect to USB devices from Android in a Go program?

2022-10-11 Thread Marko Bencun
Hi In Go, define an interface for opening the device and writing to it. Implement that interface in Java/Kotlin using the Android API for interfacing with USB. I used this without any issues in the BitBoxApp, which is an Android App that communicates with the BitBox02 hardware wallet: Go inte

[go-nuts] How to call sort.Search in a loop

2022-10-11 Thread 'ljh' via golang-nuts
Hi community, I used sort.Search on a sorted slice in below code started at Line 36, and it worked. I also tried to call sort.Search in a loop, started at Line 53. It does not seem to work. How can I correct the loop version? Thanks --- package main import ( "log" "sor

[go-nuts] Re: How to call sort.Search in a loop

2022-10-11 Thread Brian Candler
sort.Search is a binary chop, and needs an ordering condition, >= or <=. If you use == then it cannot work. In addition you're getting a panic here: if ret < len(haystack) { index += ret log.Println("found", index, haystack[index]

Re: [go-nuts] How to call sort.Search in a loop

2022-10-11 Thread K. Alex Mills
sort.Search runs binary search. It's only guaranteed to work when you provide it with a function which is monotonic -- true at index i implies true at all indices greater than i. Your loop style search does not provide a monotonic function, whereas your "upper" function is monotonic. However, sinc

Re: [go-nuts] How to call sort.Search in a loop

2022-10-11 Thread K. Alex Mills
Ah, my last post had a small mistake. A small modification to upper should be all you need. The function should use >= instead of >. See below. upper := sort.Search(len(haystack), func(i int) bool { return haystack[i].name >= needle.name }) On Tue, Oct 11, 2022, 7:38 AM K. Alex Mills wro

[go-nuts] [security] Vulnerability in golang.org/x/text/language

2022-10-11 Thread Roland Shoemaker
Hello gophers, Version v0.3.8 of golang.org/x/text fixes a vulnerability in the golang.org/x/text/language package which could cause a denial of service. An attacker can craft an Accept-Language header which ParseAcceptLanguage will take significant time to parse. This issue was discovered by OS

回复: [go-nuts] How to call sort.Search in a loop

2022-10-11 Thread 'ljh' via golang-nuts
Hi community, I improved my binary search example with both sort.Search and sort.Find.  Please correct me if I got new wrongs with new example. 1.  My original question was if there are duplicate entries in sorted slice.  After I located the first dup, how can I go to the rest of them without

[go-nuts] workspace question

2022-10-11 Thread Steve Roth
I'd appreciate help with setting up a workspace, involving two modules that exist only on my local disk and not in any SCM. I understand how to create the workspace and use both modules in it. What I can't figure out is how to add a dependency from mod1 to mod2 in mod1's go.mod file. The support

[go-nuts] The effect go test -v flag on local directory mode and package list mode

2022-10-11 Thread Jingguo Yao
I have the following directory layout: ├── bar │ └── bar_test.go ├── foo │ └── foo_test.go ├── go.mod └── go.sum foo_test.go: package main import ( "fmt" "testing" ) func TestHelloWorld(t *testing.T) { fmt.Println("hello, foo") t.Log("hi, foo") } bar_test.go: package bar

Re: [go-nuts] workspace question

2022-10-11 Thread Jan Mercl
On Wed, Oct 12, 2022 at 4:49 AM Steve Roth wrote: > > I'd appreciate help with setting up a workspace, involving two modules that exist only on my local disk and not in any SCM. I understand how to create the workspace and use both modules in it. What I can't figure out is how to add a dependenc