weakness in 'double to text' conversion

newbie nullzwei via gnumeric-list <[email protected]> Fri, 10 Dec 2021 16:21:02 +0100
Newsgroups gmane.comp.gnome.apps.gnumeric
Message-ID <trinity-048a8fc9-31f5-4199-b855-edb22cbdcb14-1639149662564@3c-app-gmx-bap27>
--===============7201861808252044138==
Content-Type: text/html; charset=UTF-8

<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div style="font-family: Verdana;font-size: 12.0px;">
<div style="font-family: Verdana;font-size: 12.0px;">
<div style="font-family: Verdana;font-size: 12.0px;">
<div style="font-family: Verdana;font-size: 12.0px;">
<div>&nbsp;<br/>
hello @all,&nbsp;<br/>
&nbsp;<br/>
I tried to use &#39;=value( text( x, &quot;0.0&quot; ) )&#39; and similar to check results of my &#39;improved calculations&#39; and control whether rounding worked correctly or went wrong.&nbsp;<br/>
&nbsp;<br/>
That worked fine until i had to compare against 1.45 . the binary &#39;nearest&#39; representation for 1.45 with IEEE doubles is &#39;undershot&#39; as 1.449999999999999955591~, and thus the rounding performed by &#39;text&#39; switches to &#39;1.4&#39; rather than &#39;1.5&#39;. &nbsp;<br/>
( same applies to plenty other values, I assume 50% of doubles for ~5 values have undershot representation )&nbsp;<br/>
&nbsp;<br/>
That is! correct from a simple POV, but wrong when accounting that the value is the representant for decimal 1.45 .<br/>
&nbsp;<br/>
( even pure &#39;C&#39; calculates &#39;printf( &quot; test: %.1f &#92;n&quot;, 1.45 ) to &#39;1.4&#39; thus this question might be better suited in other forums ... ??? )&nbsp;<br/>
&nbsp;<br/>
I could - and did - construct a workaround by evaluating a second string &#39;=value( text( x, &quot;0.000000000000000&quot; ) )&#39;, and if i find a &#39;5&#39; there in the position after the rounding limit and the &#39;text&#39; result is smaller than the origin add 0.1 to it ... but that&#39;s ... cumbersome. &nbsp;<br/>
&nbsp;<br/>
&#39;round&#39; works better for this simple case, but fails for some other values ( from a decimal POV ), and that&#39;s just my task, find the critical values where round fails, thus round doesn&#39;t help.&nbsp;<br/>
&nbsp;<br/>
Does anyone have a good idea for a &#39;elegant&#39; way to achieve ... &#39;decimal correctly rounded results for double values&#39;?&nbsp; It won&#39;t be a problem if slow or &#39;string-math&#39;, it&#39;s just needed for testing.<br/>
<br/>
Best Regards,&nbsp;<br/>
&nbsp;<br/>
&nbsp;<br/>
&nbsp;<br/>
b.<br/>
&nbsp;<br/>
P.S. please be tolerant, I&#39;m not a professional but just look, poke and try around, sometimes it results in good new things ... but not always ;-)</div>
</div>
</div>
</div>
</div></div></body></html>

--===============7201861808252044138==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
gnumeric-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/gnumeric-list

--===============7201861808252044138==--