That helps, but:
#include <stdio.h>
#include <math.h>
int main ()
{
long double d = HUGE_VAL;
printf("%.30Lf\n", d);
}
still prints just (as it should, I think):
inf
Is there maybe some way to check if a double or
long double do have a "proper" value?
You probably want something like printf("%.10Lg",d);. Here's a shot C
example and its output:
#include <stdio.h>
int main(int argc, char * argv[])
{
long double d = 0.123456789;
printf("%.30Lf\n", d);
printf("%.20Lg\n", d);
printf("%.20Le\n", d);
}
/*
0.123456788999999997336054491370
0.12345678899999999734
1.23456788999999997336e-01
*/
On Fri, Jul 17, 2009 at 6:41 PM, Maurício<briqueabra...@yahoo.com> wrote:
When we printf doubles from C (like when using hsc2hs to bind to a
constant) we can get something that's not valid Haskell. See these
2 examples:
3.40282347e+38F
inf
Do you know some way to printf a double using printf (or any other
standard function) that's always going to give me valid Haskell
text, even in special cases?
Thanks,
Maurício
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe