
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

You probably want something like printf("%.10Lg",d);. Here's a shot C
example and its output:
#include
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

That helps, but:
#include
You probably want something like printf("%.10Lg",d);. Here's a shot C example and its output:
#include
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
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

On Jul 17, 2009, at 22:27 , Maurí cio wrote:
Is there maybe some way to check if a double or long double do have a "proper" value?
isNaN :: a -> Bool True if the argument is an IEEE "not-a-number" (NaN) value isInfinite :: a -> Bool True if the argument is an IEEE infinity or negative infinity isDenormalized :: a -> Bool True if the argument is too small to be represented in normalized format isNegativeZero :: a -> Bool True if the argument is an IEEE negative zero isIEEE :: a -> Bool True if the argument is an IEEE floating point number (in Prelude, even. Class RealFloat) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

Brandon S. Allbery KF8NH wrote:
On Jul 17, 2009, at 22:27 , Maurí cio wrote:
Is there maybe some way to check if a double or long double do have a "proper" value?
isNaN :: a -> Bool True if the argument is an IEEE "not-a-number" (NaN) value
isInfinite :: a -> Bool True if the argument is an IEEE infinity or negative infinity
isDenormalized :: a -> Bool True if the argument is too small to be represented in normalized format
isNegativeZero :: a -> Bool True if the argument is an IEEE negative zero
isIEEE :: a -> Bool True if the argument is an IEEE floating point number
(in Prelude, even. Class RealFloat)
But don't trust the Prelude in Hugs (Sept2006)! The isInfinite and isNaN methods are hard-coded to answer False, ignoring the argument entirely. The logfloat package has the module Hugs.RealFloat[1] which provides correct versions (defaulting to the Prelude definitions for non-Hugs compilers). [1] http://hackage.haskell.org/packages/archive/logfloat/0.12.0.1/doc/html/Hugs-... -- Live well, ~wren
participants (4)
-
Brandon S. Allbery KF8NH
-
John Van Enk
-
Maurício
-
wren ng thornton