<div dir="ltr"><div>Hi Hongyan,<br><br></div>As Arne indicated, with 32-bit floating point, you can't expect more than 7 significant digits (14 for double), and in your case, you are asking for precision 2 orders of magnitude beyond that. <br><div><div><br></div><div>For the truly curious, all the gory reality about computing and precision/accuracy is detailed in this doc:<br></div><div><br><a href="http://www.cse.msu.edu/~cse320/Documents/FloatingPoint.pdf">http://www.cse.msu.edu/~cse320/Documents/FloatingPoint.pdf</a><br><br></div><div>HTH...<br></div><div>Rick<br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 20, 2015 at 7:26 PM, <a href="mailto:danghy@gmail.com">danghy@gmail.com</a> <span dir="ltr"><<a href="mailto:danghy@gmail.com" target="_blank">danghy@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>
<div><span></span>Hi Arne,</div><div><br></div><div>Thanks a lot for the information! I will probably use "integer" to solve the problem. But I was really curious why the floating point number returns "210200048", not "210200049"... the perfect case would be that it returns "210200051".</div><div><br></div><div>Thanks again.</div>
<div><br></div><div>Hongyan</div><hr style="width:210px;min-height:1px" align="left" color="#b5c4df" size="1">
<div><span><div style="MARGIN:10px;FONT-FAMILY:verdana;FONT-SIZE:10pt"><div><a href="mailto:danghy@gmail.com" target="_blank">danghy@gmail.com</a></div></div></span></div>
<blockquote style="margin-top:0px;margin-bottom:0px;margin-left:0.5em"><div> </div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm"><div style="PADDING-RIGHT:8px;PADDING-LEFT:8px;FONT-SIZE:12px;FONT-FAMILY:tahoma;COLOR:#000000;BACKGROUND:#efefef;PADDING-BOTTOM:8px;PADDING-TOP:8px"><div><b>From:</b> <a href="mailto:arne.melsom@met.no" target="_blank">Arne Melsom</a></div><div><b>Date:</b> 2015-07-20 17:27</div><div><b>To:</b> <a href="mailto:danghy@gmail.com" target="_blank">danghy</a></div><div><b>CC:</b> <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk</a></div><div><b>Subject:</b> Re: [ncl-talk] unexpected results from very simple code</div></div></div><div><div>Hi Danghy,</div>
<div> </div>
<div>I think that you can't expect (4 byte) floating point numbers to deliver the accuracy (no. digits) that you request. In your case, I suggest using double precision or integer representation. Here's a part of your example using the original representation and the two alternatives:</div>
<div> </div>
<div>begin</div>
<div> </div>
<div>a=210200051.</div>
<div>print("output / a :")</div>
<div>print(tostring(a))</div>
<div>print(sprintf("%9.0f",a))</div>
<div> </div>
<div>ad=210200051.d</div>
<div>print("output / ad:")</div>
<div>print(tostring(ad))</div>
<div>print(sprintf("%9.0f",ad))</div>
<div> </div>
<div>ai=210200051</div>
<div>print("output / ai:")</div>
<div>print(tostring(ai))</div>
<div>print(sprinti("%9i",ai))</div>
<div> </div>
<div>end</div>
<div> </div>
<div> </div>
<div>...which gives the following output:</div>
<div> </div>
<div>(0)        output / a :</div>
<div>(0)        210200048.000000</div>
<div>(0)        210200048</div>
<div>(0)        output / ad:</div>
<div>(0)        210200051.000000</div>
<div>(0)        210200051</div>
<div>(0)        output / ai:</div>
<div>(0)        210200051</div>
<div>(0)        210200051</div>
<div> </div>
<div>Hope this helps!</div>
<div>Arne M.</div>
<div> </div>
<div> </div>
<div> </div>
<div>----- Original Message -----</div>
<div>> Dear all,</div>
<div>> </div>
<div>> I met a problem when reading "station ID" - I've simplified the code as</div>
<div>> follows:</div>
<div>> </div>
<div>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"</div>
<div>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"</div>
<div>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"</div>
<div>> begin</div>
<div>> </div>
<div>> degrees = (/210200051, 121, 36, 43,38,58,26/)</div>
<div>> </div>
<div>> print(sprintf("%9.0f",degrees(0)))</div>
<div>> print(tostring(degrees(0)))</div>
<div>> </div>
<div>> a=210200051.</div>
<div>> print(tostring(a))</div>
<div>> print(sprintf("%9.0f",a))</div>
<div>> </div>
<div>> end</div>
<div>> </div>
<div>> The NCL output on screen is:</div>
<div>> </div>
<div>> ncl test.ncl</div>
<div>> Copyright (C) 1995-2015 - All Rights Reserved</div>
<div>> University Corporation for Atmospheric Research</div>
<div>> NCAR Command Language Version 6.3.0</div>
<div>> The use of this software is governed by a License Agreement.</div>
<div>> See <a href="http://www.ncl.ucar.edu/" target="_blank">http://www.ncl.ucar.edu/</a> for more details.</div>
<div>> (0) 210200048</div>
<div>> (0) 210200051</div>
<div>> (0) 210200048.000000</div>
<div>> (0) 210200048</div>
<div>> </div>
<div>> Only the second method "tostring" gives the correct station ID. Could you</div>
<div>> please give me a clue why is this happening?</div>
<div>> </div>
<div>> Appreciate!</div>
<div>> </div>
<div>> </div>
<div>> <a href="mailto:danghy@gmail.com" target="_blank">danghy@gmail.com</a></div>
<div>> </div>
<div>> _______________________________________________</div>
<div>> ncl-talk mailing list</div>
<div>> <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a></div>
<div>> List instructions, subscriber options, unsubscribe:</div>
<div>> <a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a></div>
<div>> </div>
</div></blockquote>
</div><br>_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>