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 <ml+prog-gol...@03s.net> 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 <math.h> 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.

Reply via email to