Re: [go-nuts] Hexadecimal floats

2019-07-26 Thread Jan Mercl
There are several NaNs, but only a single bit pattern for IEEE754 infinity
(modulo the sign bit). So yes, your suggestion should work well. Thank you,
I'll give it a try.


On Sat, Jul 27, 2019, 07:44 Adrian Ho  wrote:

> On 26/7/19 9:20 PM, Jan Mercl wrote:
> > In a program that generates C, I'm using big.Float.Text
> > (https://golang.org/pkg/math/big/#Float.Text) to produce the exact
> > value of the C floating point literal. As it turns out, the function
> > does not support Inf values. Instead of encoding the exact bits of the
> > Inf value, the resulting string is simply "Inf".
> >
> > I'm looking for possibly existing, open source Go code that does the
> > conversion properly both for C floats (Go float32) and C doubles (Go
> > float64). So far I was not able to find anything. I can surely roll my
> > own code, but I'd very much like to use a well tested code if someone
> > can point me to such.
> >
> > TIA
>
> Section 7.12.4 of the C99 standard says that  defines the
> *INFINITY* macro to represent positive infinity, and the way it's
> defined in the standard suggests that negative infinity can be
> represented by simply negating that constant. Doing it this way works
> portably across all standard C compilers and architectures.
>
> Is there a reason you can't simply post-process Text() output to replace
> "Inf" with "INFINITY"? That's just a simple "if" test.
>
> --
> Best Regards,
> Adrian
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/b6efb830-e465-fe37-8be4-27233e27d60f%4003s.net
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-XKAQd5euW%2BHLwKR5wDwYnqH8F3%3D4hVic2GTG4VW-TZjg%40mail.gmail.com.


Re: [go-nuts] Hexadecimal floats

2019-07-26 Thread Adrian Ho
On 26/7/19 9:20 PM, Jan Mercl wrote:
> In a program that generates C, I'm using big.Float.Text
> (https://golang.org/pkg/math/big/#Float.Text) to produce the exact
> value of the C floating point literal. As it turns out, the function
> does not support Inf values. Instead of encoding the exact bits of the
> Inf value, the resulting string is simply "Inf".
>
> I'm looking for possibly existing, open source Go code that does the
> conversion properly both for C floats (Go float32) and C doubles (Go
> float64). So far I was not able to find anything. I can surely roll my
> own code, but I'd very much like to use a well tested code if someone
> can point me to such.
>
> TIA

Section 7.12.4 of the C99 standard says that  defines the
*INFINITY* macro to represent positive infinity, and the way it's
defined in the standard suggests that negative infinity can be
represented by simply negating that constant. Doing it this way works
portably across all standard C compilers and architectures.

Is there a reason you can't simply post-process Text() output to replace
"Inf" with "INFINITY"? That's just a simple "if" test.

-- 
Best Regards,
Adrian

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b6efb830-e465-fe37-8be4-27233e27d60f%4003s.net.


Re: [go-nuts] Need explaination for code

2019-07-26 Thread Jan Mercl
On Fri, Jul 26, 2019 at 8:15 PM thatipelli santhosh
 wrote:

> Can anyone please explain this piece of code? this would be more helpful to 
> me to understand this. Thank you!

I don't know what "explain this code" means in this case. But maybe
this can help: https://play.golang.org/p/t4yDlOwG-rv

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-WYbwC-Udv%3Df8%3D%2BkzW4pgxTnpx_uJyvk8zwrRNt%3D60pHA%40mail.gmail.com.


Re: [go-nuts] Need explaination for code

2019-07-26 Thread Brian Hatfield
Welcome to Go!

There's a couple things going on here, which you can break down into two
overarching parts.

Part 1, var/type definition:

var testCases = []struct {
 description string
 planet  Planet
 seconds float64
 expectedfloat64
}

This says the following things:

   - Create a new variable, called testCases
   - testCases will contain a slice of (anonymous) structs ( []struct {.}
   )
   - and each of those structs will contain 4 fields: description, planet,
   seconds, expected

Part 2, the instantiation/struct literal:

{
 {
 description: "age on Earth",
 planet:  "Earth",
 seconds: 10,
 expected:31.69,
 },
 {
 description: "age on Mercury",
 planet:  "Mercury",
 seconds: 2134835688,
 expected:280.88,
 },
[etc]
}

This says:

   - Instantiate this slice of structs right in-line (this is called a
   literal)
   - Repeated anonymous struct literals for each item in the slice

The likely purpose of this code, overall, is so that later on down,
something can iterate `testCases` and get a number of `testCase`, each with
test expected values.

You could also write this code like:

type TestCase struct {
 description string
 planet  Planet
 seconds float64
 expectedfloat64
}

var testCases []TestCase

testCases = append(testCases, TestCase{
 description: "age on Uranus",
 planet:  "Uranus",
 seconds: 3210123456,
 expected:1.21,
})

[.etc]

with an append call for each case you want to add.

The example you provided just streamlines the whole process, and takes
advantage of slice literals, anonymous struct definitions, and implicit
struct literals within a slice definition.

Hope that helps!
Brian

On Fri, Jul 26, 2019 at 2:16 PM thatipelli santhosh <
santhoshthatipelli...@gmail.com> wrote:

> Hi ,
>
> I am learning Go step by step. I have go through with slices and structs
> but this below code sample is using slices and structs both at a time.
>
> Can anyone please explain this piece of code? this would be more helpful
> to me to understand this. Thank you!
>
> var testCases = []struct {
>  description string
>  planet  Planet
>  seconds float64
>  expectedfloat64
> }{
>  {
>  description: "age on Earth",
>  planet:  "Earth",
>  seconds: 10,
>  expected:31.69,
>  },
>  {
>  description: "age on Mercury",
>  planet:  "Mercury",
>  seconds: 2134835688,
>  expected:280.88,
>  },
>  {
>  description: "age on Venus",
>  planet:  "Venus",
>  seconds: 189839836,
>  expected:9.78,
>  },
>  {
>  description: "age on Mars",
>  planet:  "Mars",
>  seconds: 2329871239,
>  expected:39.25,
>  },
>  {
>  description: "age on Jupiter",
>  planet:  "Jupiter",
>  seconds: 901876382,
>  expected:2.41,
>  },
>  {
>  description: "age on Saturn",
>  planet:  "Saturn",
>  seconds: 30,
>  expected:3.23,
>  },
>  {
>  description: "age on Uranus",
>  planet:  "Uranus",
>  seconds: 3210123456,
>  expected:1.21,
>  },
>  {
>  description: "age on Neptune",
>  planet:  "Neptune",
>  seconds: 8210123456,
>  expected:1.58,
>  },
> }
>
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/de5ac14e-0f10-4e84-ae07-10aecd9eb11d%40googlegroups.com
> 
> .
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANGiwgZaYALN-YQk75DoHQ-P1hSvsnz6AC_14%3DL51sPFq0WZoA%40mail.gmail.com.


[go-nuts] Need explaination for code

2019-07-26 Thread thatipelli santhosh
Hi ,

I am learning Go step by step. I have go through with slices and structs 
but this below code sample is using slices and structs both at a time.

Can anyone please explain this piece of code? this would be more helpful to 
me to understand this. Thank you!

var testCases = []struct {
 description string
 planet  Planet
 seconds float64
 expectedfloat64
}{
 {
 description: "age on Earth",
 planet:  "Earth",
 seconds: 10,
 expected:31.69,
 },
 {
 description: "age on Mercury",
 planet:  "Mercury",
 seconds: 2134835688,
 expected:280.88,
 },
 {
 description: "age on Venus",
 planet:  "Venus",
 seconds: 189839836,
 expected:9.78,
 },
 {
 description: "age on Mars",
 planet:  "Mars",
 seconds: 2329871239,
 expected:39.25,
 },
 {
 description: "age on Jupiter",
 planet:  "Jupiter",
 seconds: 901876382,
 expected:2.41,
 },
 {
 description: "age on Saturn",
 planet:  "Saturn",
 seconds: 30,
 expected:3.23,
 },
 {
 description: "age on Uranus",
 planet:  "Uranus",
 seconds: 3210123456,
 expected:1.21,
 },
 {
 description: "age on Neptune",
 planet:  "Neptune",
 seconds: 8210123456,
 expected:1.58,
 },
}


-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/de5ac14e-0f10-4e84-ae07-10aecd9eb11d%40googlegroups.com.


[go-nuts] Yaegi – Yet Another Go Interpreter by the Traefik team from Containous

2019-07-26 Thread Cleverson Casarin Uliana
This is great especially for beginner and hobbist programmers; thank
you very much.

Greetings,
Cleverson

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMnvY35XeZg%3DS-4gZTunwUn01qUvD6kkdyOLrD0xHP8%3Domd%3DQw%40mail.gmail.com.


[go-nuts] Gophercon 2019 videos?

2019-07-26 Thread gary . willoughby
With the recent Gophercon being held I wonder if any videos have been 
posted of the talks? I'm especially interested in the move to Go 2 and the 
plans for generics.

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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/087f893f-54ea-4692-8edf-34e22dd973a4%40googlegroups.com.


[go-nuts] Hexadecimal floats

2019-07-26 Thread Jan Mercl
In a program that generates C, I'm using big.Float.Text
(https://golang.org/pkg/math/big/#Float.Text) to produce the exact
value of the C floating point literal. As it turns out, the function
does not support Inf values. Instead of encoding the exact bits of the
Inf value, the resulting string is simply "Inf".

I'm looking for possibly existing, open source Go code that does the
conversion properly both for C floats (Go float32) and C doubles (Go
float64). So far I was not able to find anything. I can surely roll my
own code, but I'd very much like to use a well tested code if someone
can point me to such.

TIA

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAA40n-WTVTm2LoYYdVBF2JOeCEDfRKT-8r1BApuESRDLVo-oRQ%40mail.gmail.com.


Re: [go-nuts] P-local/M-local storage for goroutines?

2019-07-26 Thread Robert Engels
Well, you can on modern commercial processors for local guards. 

It is also very easy to reason why - most lock structures use the same CAS 
constructs behind the scenes so you are eliminating operations in all cases. 

When you say “faster” you probably mean “fairer” - as most lock free algorithms 
can starve /bias actors and in many cases you don’t this. For a write through 
cache (which this most likely is) you definitely want lock free structures 
(unless it is biased towards writes and in this case you probably don’t want a 
cache at all). 

This doesn’t even get into the performance possibilities of using eventually 
consistent/lazy methods which are even faster. 

All of this is predicated on proper implementation - you can review the 
github/robaho/go-concurrency-test to see where Go falls down a bit here. 

> On Jul 26, 2019, at 4:49 AM, Jesper Louis Andersen 
>  wrote:
> 
>> On Thu, Jul 25, 2019 at 1:47 PM Robert Engels  wrote:
> 
>> A sync.Map is lock free on read, and a single lock on writes and so will out 
>> perform this solution in all cases. 
>> 
> 
> I wouldn't just matter-of-factly place lock-free algorithms above classical 
> mutex locks in speed. 

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/9143EBE6-77F8-4E98-9D4C-98C03686E16D%40ix.netcom.com.


Re: [go-nuts] P-local/M-local storage for goroutines?

2019-07-26 Thread Jesper Louis Andersen
On Thu, Jul 25, 2019 at 1:47 PM Robert Engels  wrote:

> A sync.Map is lock free on read, and a single lock on writes and so will
> out perform this solution in all cases.
>
>
I wouldn't just matter-of-factly place lock-free algorithms above classical
mutex locks in speed.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGrdgiUKEe0_TbrFHeGjm6Z-Be7AYphRBLr9d0Vrd1bvYeYZMA%40mail.gmail.com.