Re: Possible bug in "tostring" function

From: Wei Huang <huangwei_at_nyahnyahspammersnyahnyah>
Date: Thu Jul 03 2014 - 16:25:43 MDT

Dave,

I do not think this is a bug with this case.
tostring simple use "%f" to convert float to string,
and for this case, the last digit is at the border of its precision.
You may try to use a double which works better at this situation.
Or you may try:

 bsf = tostring_with_format(b, "%8.5f")
 print(bsf)

Regards,

Wei







On Thu, Jul 3, 2014 at 3:32 PM, David Jones <jonesd647@yahoo.ca> wrote:

> Greetings NCL,
>
> Firstly, I'd like to commend you on the wonderful software that is NCL. I
> think it's wonderful.
>
> Secondly, I'd like to report that I may have found a bug in the *tostring*
> function...
>
> When I round a float using *decimalPlaces* and then convert that float to
> a string, the string matches the unrounded number instead of the rounded
> one.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *ncl 0> a=32.328739ncl 1> load
> "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" ncl 2>
> b=decimalPlaces(a,5,True)ncl 3> print(b)Variable: bType: floatTotal Size: 4
> bytes 1 valuesNumber of Dimensions: 1Dimensions and sizes:
> [1]Coordinates: (0) 32.32874 ncl 4> c=tostring(b)ncl 5>
> print(c)Variable: cType: stringTotal Size: 8 bytes 1
> valuesNumber of Dimensions: 1Dimensions and sizes: [1]Coordinates:
> (0) 32.328739*
>
> This behavior only seems to happen with certain numbers, but I can't quite
> see a pattern as to which numbers are affected. I only need to round to 5
> decimal places, so I'm not sure if other roundings can be similarly
> affected.
>
> Could you please clarify is this is a bug, or if I've somehow
> misunderstood the correct usage of the function. For further information,
> I'm using ncl version 6.1.2 on a 64-bit Linux system (I installed the
> Debian gcc455 binary).
>
> With best regards,
> Dave.
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>

Received on Thu Jul 03 10:26:20 2014

This archive was generated by hypermail 2.1.8 : Wed Jul 23 2014 - 15:33:46 MDT