Re: [go-nuts] Having difficulty converting []byte to float

2018-05-17 Thread Jesse McNelis
On Fri, May 18, 2018 at 12:26 PM,   wrote:
> Hello all.  I am creating a custom exporter for FreeNAS
> https://github.com/Maelos/freenas_exporter and am stuck on the conversion of
> the string of bytes provided by the commands output to a float.  Here is my
> code, what I have tried, and my results:
>
> What I have tried and results (commented so you can try and see each
> https://play.golang.org/p/sevfk7Nt2w4

> Attempt 1 = binary.LittleEndian.Uint64([]bytes) to math.Float64frombits

You've got a 2 byte slice, but you need 8 bytes. You're getting an
'index out of range' because you need a slice of 8 bytes.


> Attempt 3 = Bytes to bytes.Reader to binary.Read(slice of bytes,
> binary.LittleEndian, floatVariableToFill) to error check

You've got 2 bytes in your bytes.Reader and you're trying to read 8
bytes from it, this is why you get an error.
A float64 is 8 bytes so you need at least 8 bytes in your bytes.Reader.

> Attempt 2 = bytes to string, String to float (strconv)

You are parsing the string "2\n" which isn't a string representation
of a float. So that's not going to work.
The fact that these bytes are ascii characters means that your other
attempts don't make a lot of sense. The ascii value for the character
'2' is 50 so even if your other attempts worked you'd get a float with
50 instead of the 2 you're expecting.

If you do f, err :=
strconv.ParseFloat(strings.TrimSpace(string(text)), 64) you'll trim
off the invalid '\n' and you'll just have a '2' that will parse
correctly.

-- 
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: Cgo: using syscall.Select

2018-05-17 Thread Сергей Камардин
You could also take a look 
at https://godoc.org/github.com/mailru/easygo/netpoll

четверг, 17 мая 2018 г., 3:08:29 UTC+3 пользователь Juliusz Chroboczek 
написал:
>
> I'm interfacing with a C library that expects to do its own I/O, but 
> wants to be called after a file descriptor is ready for read.  My code 
> currently looks roughly like this: 
>
> var fdset syscall.FdSet 
> var bits = unsafe.Sizeof(fdset.Bits[0]) * 8 
> fdset.Bits[uintptr(fd)/bits] |= (1 << (fd % bits)) 
> var ctv C.struct_timeval 
> C.gettimeout(&ctv) 
> tv := syscall.Timeval{int64(ctv.tv_sec), int64(ctv.tv_usec)} 
> n, err := syscall.Select(int(fd + 1), &fdset, nil, nil, &tv) 
> if n < 0 { 
> return err 
> } 
> rc, err := C.dostuff(fd) 
> if(rc < 0) { 
> return err 
> } 
>
> I'm bothered by two things: 
>
>   - the way I access the syscall.FdSet feels like an unportable hack; 
>   - I'd much rather hook into Go's scheduler then burn a thread on 
> sleeping in select. 
>
> Is the above the correct way to interface with the C library, or is 
> there a better way? 
>
>

-- 
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] Having difficulty converting []byte to float

2018-05-17 Thread Tamás Gulácsi
The input is string, so use strconv.ParseFloat, or ParseInt (will there be 
non-integer number of cpus?)
Just trim the LF with strings.TrimSpace.

For production use, leave out the grep and bash, read the output lines directly 
with bufio.Scanner.

-- 
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] Having difficulty converting []byte to float

2018-05-17 Thread john . macrae . fox
Hello all.  I am creating a custom exporter for 
FreeNAS https://github.com/Maelos/freenas_exporter and am stuck on the 
conversion of the string of bytes provided by the commands output to a 
float.  Here is my code, what I have tried, and my results:

What I have tried and results (commented so you can try and see each 
https://play.golang.org/p/sevfk7Nt2w4

Attempt 1 = binary.LittleEndian.Uint64([]bytes) to math.Float64frombits
Attempt 2 = bytes to string, String to float (strconv)
Attempt 3 = Bytes to bytes.Reader to binary.Read(slice of bytes, 
binary.LittleEndian, floatVariableToFill) to error check

Please let me know what more I can provide.  I will keep hacking away at it 
tomorrow, but hoping I can get this done soon.  Full go play write up below:

package main


import (
 //You may need to edit these in or out depending upon the attempt
 "bytes"
 "encoding/binary"
 "fmt"
 //"strconv"
 //"math"
)


func main() {


 // I have been able to test this part and I do get a return of "[50 10]" 
which is correct (converts string "2" for 2 CPUs).  The exact statement may 
be a bit different.
 // I am running the script on the latest FreeNAS whic his built from 
11.1STABLE FreeBSD.  I have Go installed and am building the files on the 
shell
 //numCPUCmd := exec.Command("bash", "-c","/usr/local/bin/ipmitool -I 
lanplus -H ipmiAddress -U ipmiUser -f /root/ipmi_password sdr elist all | 
grep -c -i \"cpu.*temp\"")
 //numCPUBytes, _ := numCPUCmd.Output() //returns a slice of bytes and an 
error




 // ATTEMPT 1
 var flty float64
 sob := []byte{50, 10}
 fmt.Printf("\n%T %v\n\n", sob, sob)


 buf := bytes.NewReader(sob)
 err := binary.Read(buf, binary.LittleEndian, &flty)
 if err != nil {
 fmt.Println("binary.Read failed:", err)
 }
 fmt.Println(flty)
 
 /*Result
 []uint8 [50 10]


 binary.Read failed: unexpected EOF
 0
 */
 
 
 //ATTEMPT 2
 /*
 var f float64
text := []byte{50, 10} // A decimal value represented as Latin-1 text


f, err := strconv.ParseFloat(string(text), 64)
if err != nil {
panic(err)
}
fmt.Println(f)
 */
 /*Result
 panic: strconv.ParseFloat: parsing "2\n": invalid syntax


 goroutine 1 [running]:
 main.main()
 /tmp/sandbox657430918/main.go:44 +0x160
 */
 
 
 //ATTEMPT3
 /*
 sob := []byte{50, 10}
 bits := binary.LittleEndian.Uint64(sob)
 fmt.Printf("\n\n%T %v\n\n", bits, bits)


 flty := math.Float64frombits(bits)
 fmt.Printf("\n\n%T %v\n\n", flty, flty)


 inty := int(flty)
 fmt.Printf("\n\n%T %v\n\n", inty, inty)
 */
 /* Result
 panic: runtime error: index out of range


 goroutine 1 [running]:
 encoding/binary.binary.littleEndian.Uint64(...)
 /usr/local/go/src/encoding/binary/binary.go:76
 main.main()
 /tmp/sandbox742704811/main.go:62 +0x20
 */
}

-- 
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] Re: Go license and fitness for purpose

2018-05-17 Thread Dave Cheney
Thank you to all those who contributed to this thread. While many Go 
programs are written under open source licences, and many Go programmers 
contribute to open source in a professional or personal capability, it is 
now time to bring the discussion to a close as this thread has moved 
outside the scope of this mailing list.

Please feel free to continue this discussion in other forums.

Thanks

Dave

On Friday, 18 May 2018 05:39:59 UTC+10, matthe...@gmail.com wrote:
>
> Thanks for responding Michael.
>
> "decorative item not to be used off-road, in uneven terrain, or relied 
>> upon as protection in case of vehicle roll."
>
>
> The sticker I’ve been looking at says something like “modifying or 
> attaching anything to this ROPS will compromise the structure and may cause 
> injury or death” and I had a relative roll a tractor last year but is 
> luckily ok.
>
> I understand being conservative for the courts, but GCC and Go can make 
> programs for computers that can do safety applications reliably. People 
> maybe do with GCC derivatives. People do with Ada or C (and Go maybe is 
> less mistake-prone than C at the language level).
>
> Leveraging the work of an open or free project and contributing back 
> improvements found in testing seems like a good idea to me for liable 
> ventures and for the reliability of minimal liability uses that Google does 
> with Go and maybe GCC. I don’t think these compiler projects should take on 
> unnecessary liability, but one thing that can be done is to be sure there 
> aren’t any intentional mistakes, backdoors, or practical jokes as allowed 
> under the licenses. I'd like to guarantee that to liable ventures and it's 
> a free win for general purpose computing anyway.
>
> Matt
>
> On Thursday, May 17, 2018 at 12:18:30 PM UTC-5, Michael Jones wrote:
>>
>> perhaps some context will make this clearer. no reference is being made 
>> to any actual persons or events.
>>
>> 1. It is the observed habit of people (plaintiff's) bring suit in court 
>> when something goes wrong. 
>> Ex: airplane crash, dark spot on potato chip, food is too hot, etc.
>>
>> 2. Plaintiff's attorneys have developed the habit of including everyone 
>> possible in the "bag guy" list; this creates a kind of mutual fund where 
>> everyone can settle for $10,000 and that, multiplied by 100 defendants, is 
>> $1M. The attorney gets 1/3 of that, so attorneys drive nice cars and fly 
>> first class.
>> Ex: car accident with fire.: sue the car company, the airbag company, the 
>> brake pad company, the glass company, the bumper designer, , the gas 
>> station, the gas transport truck, the oil refinery,...,the tire company, 
>> the person who designed the tire treads, etc.
>>
>> 3. After 60+ years of this, everyone who is wise to the situation sells 
>> retail products that specifically disclaim every possible dangerous use, 
>> and as many kinds of critical or life-safety misuse as can be foreseen, and 
>> wholesale products where every possible liability passes to the purchaser 
>> as a condition of sale. 
>> Ex: "You agree to not use the APIs for any activities where the use or 
>> failure of the APIs could lead to death, personal injury, or environmental 
>> damage (such as the operation of nuclear facilities, air traffic control, 
>> or life support systems)."
>>
>> 4. After 40+ years of open source having an observable footprint, open 
>> source entities, corporate contributors, and individuals have found that 
>> this style of "universal disclaimer" is an important defensive bulwark. 
>> Most people would not want to lose their house and savings as the result of 
>> contributing code to a matrix library that happens to be used in the 
>> science payload of a space project where the rocket engines explode on 
>> launch and the resulting fires and fumes cause problems for miles around 
>> resulting in a class-action suit for much of Florida. (crazy made-up 
>> example but perhaps it makes clear the idea of minimizing exposure to legal 
>> risks associated in no logical way with individual action.)
>>
>> This is the context in which various excuse-laden, 
>> suitability-disclaiming, crazy-seeming license agreements arise.
>>
>> As a real example, but with the name removed, I once saw in a parking lot 
>> a new pickup truck made by a well-known Japanese car manufacturer. It had a 
>> shiny chrome tubular framework rising up from the bed of the truck just 
>> behind the cab. The framework had lights attached. It have the truck a 
>> tough, off-road character. I said to my wife, "wow, that's quite the 
>> roll-bar for a little truck. Look how thick the tubes are." She said, there 
>> is a sticker on it what does it say. We looked, it read:  "decorative item 
>> not to be used off-road, in uneven terrain, or relied upon as protection in 
>> case of vehicle roll."
>>
>> That is the real world of litigious people, 1/3 hungry attorneys, and 
>> juries that like to "do something" when there is a victim.
>

Re: [go-nuts] Re: Go license and fitness for purpose

2018-05-17 Thread matthewjuran
Thanks for responding Michael.

"decorative item not to be used off-road, in uneven terrain, or relied upon 
> as protection in case of vehicle roll."


The sticker I’ve been looking at says something like “modifying or 
attaching anything to this ROPS will compromise the structure and may cause 
injury or death” and I had a relative roll a tractor last year but is 
luckily ok.

I understand being conservative for the courts, but GCC and Go can make 
programs for computers that can do safety applications reliably. People 
maybe do with GCC derivatives. People do with Ada or C (and Go maybe is 
less mistake-prone than C at the language level).

Leveraging the work of an open or free project and contributing back 
improvements found in testing seems like a good idea to me for liable 
ventures and for the reliability of minimal liability uses that Google does 
with Go and maybe GCC. I don’t think these compiler projects should take on 
unnecessary liability, but one thing that can be done is to be sure there 
aren’t any intentional mistakes, backdoors, or practical jokes as allowed 
under the licenses. I'd like to guarantee that to liable ventures and it's 
a free win for general purpose computing anyway.

Matt

On Thursday, May 17, 2018 at 12:18:30 PM UTC-5, Michael Jones wrote:
>
> perhaps some context will make this clearer. no reference is being made to 
> any actual persons or events.
>
> 1. It is the observed habit of people (plaintiff's) bring suit in court 
> when something goes wrong. 
> Ex: airplane crash, dark spot on potato chip, food is too hot, etc.
>
> 2. Plaintiff's attorneys have developed the habit of including everyone 
> possible in the "bag guy" list; this creates a kind of mutual fund where 
> everyone can settle for $10,000 and that, multiplied by 100 defendants, is 
> $1M. The attorney gets 1/3 of that, so attorneys drive nice cars and fly 
> first class.
> Ex: car accident with fire.: sue the car company, the airbag company, the 
> brake pad company, the glass company, the bumper designer, , the gas 
> station, the gas transport truck, the oil refinery,...,the tire company, 
> the person who designed the tire treads, etc.
>
> 3. After 60+ years of this, everyone who is wise to the situation sells 
> retail products that specifically disclaim every possible dangerous use, 
> and as many kinds of critical or life-safety misuse as can be foreseen, and 
> wholesale products where every possible liability passes to the purchaser 
> as a condition of sale. 
> Ex: "You agree to not use the APIs for any activities where the use or 
> failure of the APIs could lead to death, personal injury, or environmental 
> damage (such as the operation of nuclear facilities, air traffic control, 
> or life support systems)."
>
> 4. After 40+ years of open source having an observable footprint, open 
> source entities, corporate contributors, and individuals have found that 
> this style of "universal disclaimer" is an important defensive bulwark. 
> Most people would not want to lose their house and savings as the result of 
> contributing code to a matrix library that happens to be used in the 
> science payload of a space project where the rocket engines explode on 
> launch and the resulting fires and fumes cause problems for miles around 
> resulting in a class-action suit for much of Florida. (crazy made-up 
> example but perhaps it makes clear the idea of minimizing exposure to legal 
> risks associated in no logical way with individual action.)
>
> This is the context in which various excuse-laden, 
> suitability-disclaiming, crazy-seeming license agreements arise.
>
> As a real example, but with the name removed, I once saw in a parking lot 
> a new pickup truck made by a well-known Japanese car manufacturer. It had a 
> shiny chrome tubular framework rising up from the bed of the truck just 
> behind the cab. The framework had lights attached. It have the truck a 
> tough, off-road character. I said to my wife, "wow, that's quite the 
> roll-bar for a little truck. Look how thick the tubes are." She said, there 
> is a sticker on it what does it say. We looked, it read:  "decorative item 
> not to be used off-road, in uneven terrain, or relied upon as protection in 
> case of vehicle roll."
>
> That is the real world of litigious people, 1/3 hungry attorneys, and 
> juries that like to "do something" when there is a victim.
>
> On Thu, May 17, 2018 at 8:48 AM > wrote:
>
>> I was thinking something like writing an undocumented “Happy New Year!” 
>> to standard out at the start of the year. An obvious but undocumented ‘rm 
>> -rf /‘ attempt was mentioned above.
>>
>> My first program was a practical joke. On the calculator command line I 
>> said “press enter” then put the program call on the next line. The program 
>> would scroll some text forever. The command display state was preserved 
>> through being turned off, so somebody in the next class pressed enter then 
>> had their calculator lo

Re: [go-nuts] Re: Go license and fitness for purpose

2018-05-17 Thread Michael Jones
perhaps some context will make this clearer. no reference is being made to
any actual persons or events.

1. It is the observed habit of people (plaintiff's) bring suit in court
when something goes wrong.
Ex: airplane crash, dark spot on potato chip, food is too hot, etc.

2. Plaintiff's attorneys have developed the habit of including everyone
possible in the "bag guy" list; this creates a kind of mutual fund where
everyone can settle for $10,000 and that, multiplied by 100 defendants, is
$1M. The attorney gets 1/3 of that, so attorneys drive nice cars and fly
first class.
Ex: car accident with fire.: sue the car company, the airbag company, the
brake pad company, the glass company, the bumper designer, , the gas
station, the gas transport truck, the oil refinery,...,the tire company,
the person who designed the tire treads, etc.

3. After 60+ years of this, everyone who is wise to the situation sells
retail products that specifically disclaim every possible dangerous use,
and as many kinds of critical or life-safety misuse as can be foreseen, and
wholesale products where every possible liability passes to the purchaser
as a condition of sale.
Ex: "You agree to not use the APIs for any activities where the use or
failure of the APIs could lead to death, personal injury, or environmental
damage (such as the operation of nuclear facilities, air traffic control,
or life support systems)."

4. After 40+ years of open source having an observable footprint, open
source entities, corporate contributors, and individuals have found that
this style of "universal disclaimer" is an important defensive bulwark.
Most people would not want to lose their house and savings as the result of
contributing code to a matrix library that happens to be used in the
science payload of a space project where the rocket engines explode on
launch and the resulting fires and fumes cause problems for miles around
resulting in a class-action suit for much of Florida. (crazy made-up
example but perhaps it makes clear the idea of minimizing exposure to legal
risks associated in no logical way with individual action.)

This is the context in which various excuse-laden, suitability-disclaiming,
crazy-seeming license agreements arise.

As a real example, but with the name removed, I once saw in a parking lot a
new pickup truck made by a well-known Japanese car manufacturer. It had a
shiny chrome tubular framework rising up from the bed of the truck just
behind the cab. The framework had lights attached. It have the truck a
tough, off-road character. I said to my wife, "wow, that's quite the
roll-bar for a little truck. Look how thick the tubes are." She said, there
is a sticker on it what does it say. We looked, it read:  "decorative item
not to be used off-road, in uneven terrain, or relied upon as protection in
case of vehicle roll."

That is the real world of litigious people, 1/3 hungry attorneys, and
juries that like to "do something" when there is a victim.

On Thu, May 17, 2018 at 8:48 AM  wrote:

> I was thinking something like writing an undocumented “Happy New Year!” to
> standard out at the start of the year. An obvious but undocumented ‘rm -rf
> /‘ attempt was mentioned above.
>
> My first program was a practical joke. On the calculator command line I
> said “press enter” then put the program call on the next line. The program
> would scroll some text forever. The command display state was preserved
> through being turned off, so somebody in the next class pressed enter then
> had their calculator lock up and I got in trouble because the teacher had
> to remove the batteries. I had an effect on many people because of the lost
> class time. I explained that there was a key to interrupt any program.
>
> These university licenses allow newcomers to programming to make that kind
> of social mistake and I think it’s right to not punish them for it. I might
> not be a programmer if I had gotten detention for the calculator program,
> and things like GCC might not exist without some wild thinking. I don’t
> think this approach is right for industry, other serious ventures, and
> especially not for safety focused applications though.
>
> It looks like the Intel corporate family thinks Intel, ARM, and Power
> architecture processor implementations are trustworthy enough for safety
> applications. There’s this OS called VxWorks said on the website to be
> intended for safe IoT device applications:
> https://www.windriver.com/products/vxworks/
>
> It appears that WindRiver has worked with the GCC project for the VxWorks
> platform:
> https://www.windriver.com/products/product-notes/tornado2/gnu_relnote.pdf
>
> QNX has a C/C++ toolchain for ARM and x86:
> http://blackberry.qnx.com/en/products/certified_os/safe-kernel
>
> Here’s a 2011 thread about Go and RTOS:
> https://groups.google.com/forum/#!topic/golang-nuts/95BJqJvb7I0
>
> There there’s a claim that the garbage collector makes Go unusable in
> real-time operating systems, but I think

Re: [go-nuts] Re: Go license and fitness for purpose

2018-05-17 Thread matthewjuran
I was thinking something like writing an undocumented “Happy New Year!” to 
standard out at the start of the year. An obvious but undocumented ‘rm -rf 
/‘ attempt was mentioned above.

My first program was a practical joke. On the calculator command line I 
said “press enter” then put the program call on the next line. The program 
would scroll some text forever. The command display state was preserved 
through being turned off, so somebody in the next class pressed enter then 
had their calculator lock up and I got in trouble because the teacher had 
to remove the batteries. I had an effect on many people because of the lost 
class time. I explained that there was a key to interrupt any program.

These university licenses allow newcomers to programming to make that kind 
of social mistake and I think it’s right to not punish them for it. I might 
not be a programmer if I had gotten detention for the calculator program, 
and things like GCC might not exist without some wild thinking. I don’t 
think this approach is right for industry, other serious ventures, and 
especially not for safety focused applications though.

It looks like the Intel corporate family thinks Intel, ARM, and Power 
architecture processor implementations are trustworthy enough for safety 
applications. There’s this OS called VxWorks said on the website to be 
intended for safe IoT device applications: 
https://www.windriver.com/products/vxworks/

It appears that WindRiver has worked with the GCC project for the VxWorks 
platform: 
https://www.windriver.com/products/product-notes/tornado2/gnu_relnote.pdf

QNX has a C/C++ toolchain for ARM and x86: 
http://blackberry.qnx.com/en/products/certified_os/safe-kernel

Here’s a 2011 thread about Go and RTOS: 
https://groups.google.com/forum/#!topic/golang-nuts/95BJqJvb7I0

There there’s a claim that the garbage collector makes Go unusable in 
real-time operating systems, but I think there are cases where real-time is 
less important than the OS being developed with reliability in mind. Maybe 
Go could be very useful on RTOS platforms.

My understanding is the intent for Go is to solve problems at Google. I 
think involving varying outside uses of Go will help Google by making a 
toolchain more robust than just Google applications will do, and I think 
the design of the Go language is ideal for a next generation of general 
purpose software like C was before. And I hope this thread adds value.

“No features contrary to documentation” seems like a mistake since 
documentation is usually not right. “No obfuscated features or obviously 
wrong features” seems too vague and may invite incorrect claims. “This 
software has no effects except for documented or obvious use”? Obviously a 
lawyer would have to translate it to match case results and other lawyer 
things, and those writing software under the license would have to be aware 
of the implications. I plan to email a summary of this discussion to FSF 
and OSI mailing lists.

Thanks,
Matt

On Wednesday, May 16, 2018 at 8:55:09 PM UTC-5, kortschak wrote:
>
> I hope so. I provide a package (github.com/kortschak/zalgo) that I 
> cannot promise will not summon demons. It was written intentionally as 
> a joke. I disclaim all liability should use of the package bring about 
> meetings with demonic presences. 
>
> On Wed, 2018-05-16 at 07:25 -0700, matthe...@gmail.com  
> wrote: 
> > I think practical jokes should be allowed under the GPL, BSD, and 
> > similar  
> > licenses. 
>

-- 
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: Encoding

2018-05-17 Thread Manlio Perillo
Il giorno giovedì 17 maggio 2018 04:57:48 UTC+2, Raulino Neto ha scritto:
>
> Hello Guys, I have to convert a Json to a UTF_16LE and byte array for sign 
> a rsa key, someone have idea that how I can do it? Thanks regards.
>

For encoding UTF-8 to UTF-16LE see:
https://godoc.org/golang.org/x/text/encoding/unicode

And here is the first example I found on google:
https://stackoverflow.com/questions/32518432/how-to-convert-from-an-encoding-to-utf-8-in-go


Manlio 

-- 
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] Cgo: using syscall.Select

2018-05-17 Thread Ian Lance Taylor
On Thu, May 17, 2018 at 9:56 AM, Juliusz Chroboczek  wrote:
>> If you do this in Go, you should use golang.org/x/sys/unix package
>> rather than the syscall package.
>
> What's the advantage?  (In this particular case, not in general.)

The advantage in this particular case is likely minimal.  The main
advantage is portability.  For example, Go runs on Solaris, but the
syscall package does not support syscall.Select on Solaris.  The
golang.org/x/sys/unix package does.

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.


[go-nuts] Re: How to calculate x^y? (the power of)

2018-05-17 Thread Louki Sumirniy
math/big's big.Int has a power function: 
https://golang.org/pkg/math/big/#Int.Exp

I wrote a power function for big.Float you can find 
here: https://github.com/l0k1verloren/float256/blob/master/float256.go#L82 
It doesn't check for overflows because I don't think big.Float overflows 
from 64 bit exponents though maybe it could from a big enough base.

On Wednesday, 11 July 2012 06:22:15 UTC+3, Ondekoza wrote:
>
> How do I idiomatically calculate "the power of" with integers?
>
> z := 3^4 // Nooo, ^ caret is bitwise negation
> z := 3**4 // Nooo, invalid indirect
> z := math.Pow(3,4) // Correct, but converting 3 and 4 to float, and the 
> result.
> BigInt? I cannot provide an example, because I cannot understand from the 
> docs how to convert a 3 to a Bigint.
>
> Is the big package (using ints) better or converting to float first (using 
> the math-package)? 
> Would you see 2^x as a special case (using shifting)?
>
>
>

-- 
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] Cgo: using syscall.Select

2018-05-17 Thread Juliusz Chroboczek
> If you do this in Go, you should use golang.org/x/sys/unix package
> rather than the syscall package.

What's the advantage?  (In this particular case, not in general.)

> But since you have to call C anyhow, I would suggest just doing it in C.

Yeah, I guess it's simpler.

> There isn't any way to hook into Go's scheduler for this.  Go's
> scheduler provides no mechanism for waiting for data without reading
> the data.

I suppose it makes sense, the operation might be difficult to implement in
a hypothetical scheduler that's layered over mainframe-style async operations.

Thanks for your reply,

-- Juliusz

-- 
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.