<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<br>
<font face="Courier New">Antoine,<br>
<br>
Thanks for the link, very interesting.<br>
<br>
Regards,<br>
<br>
Federico Miyara<br>
</font><br>
<div class="moz-cite-prefix">On 06/01/2021 05:22, Antoine Monmayrant
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:50c5a7e2-7d7e-e3c7-d83f-eb76ec1b1a0f@laas.fr">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<p>Hello Frederico,</p>
<p>Like Christophe, I am not sure this has anything to do with the
implementation of sin().<br>
It seems to be a known limitation of numerical calculations
using floating numbers.<br>
In particular, even with en hypothetical ideal value of %pi,
because of the conversion to a double, %pi*1e15 is converted to
the nearest available double and this "shift" or error as
compared to the ideal infinitely-precise value is increasing
with the size of your number.<br>
Thus you make a x1e15 bigger error when using "%pi*1e15" than
when using "%pi".<br>
As Christophe as said, there is not much you can do, apart from
resorting to symbolic calculation (what Alpha does).</p>
<p>You can see that by using nearfloat to get the distance between
two doubles:</p>
<blockquote>
<p>nearfloat("succ", %pi)-%pi<br>
ans = 4.441D-16<br>
nearfloat("succ", %pi*1e15)-%pi*1e15<br>
ans = 0.5<br>
</p>
</blockquote>
<p>As I said, the error on the sin() argument is getting x1e15
bigger!<br>
</p>
<p>I'm sorry if my explanation of floating point numbers is not
really good.<br>
This one was a revelation for me: <a
class="moz-txt-link-freetext"
href="https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html"
moz-do-not-send="true">https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html</a>
.<br>
It helped me understand why it's usually a good idea to use
"reduced units" for your calculations (ie keep everything close
to 1 when possible).</p>
<p>I hope it helps,</p>
<p>Cheers,<br>
</p>
Antoine
<div class="moz-cite-prefix">On 05/01/2021 09:19, Federico Miyara
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:612f5b66-b72e-5194-5bd3-a37f37b84aba@fceia.unr.edu.ar">
<meta http-equiv="content-type" content="text/html;
charset=UTF-8">
<br>
<font face="Courier New">Dear all,<br>
<br>
In order to test the FFT on a periodic signal whose period is
an exact submultiple of the FFT length I found a frequency fo
satisfying this for the chosen sample rate and window length,
and generated the following signal:<br>
<br>
x = sin(2*%pi*fo*t); <br>
<br>
where t is a time vector. This should be a perfectly periodic
discrete signal but it isn't because the sin() function has a
(virtually) exact period of pi, while %pi is exact to 16
digits only.<br>
<br>
For instance, we have (23 digits shown)<br>
<br>
--> sin(%pi)<br>
ans =<br>
0.0000000000000001224647<br>
<br>
--> sin(1e10*%pi)<br>
ans =<br>
-0.0000022393627619559233<br>
<br>
--> sin(1e15*%pi)<br>
ans =<br>
-0.2362090532517409080526<br>
<br>
The Wolfram Alpha site yields the correct value 0 in all cases
(using their own pi).<br>
<br>
Questions:<br>
<br>
1) How is the sin() function extended to very large values of
the argument? My first guess would be to compute a quarter
cycle using Taylor and then extend it by symmetry and
periodicity, but with which period? The best approximation
available is 2*%pi. Or it is possible to use extended
precision internally?<br>
<br>
2) Is there a way to get a periodic discrete sine other than
extending it periodically with the desired period?<br>
Wouldn't this create a slight glitch at the frontier between
cycles?<br>
<br>
Regards,<br>
<br>
Federico Miyara <br>
</font>
<div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br>
<table style="border-top: 1px solid #D3D4DE;">
<tbody>
<tr>
<td style="width: 55px; padding-top: 18px;"><a
href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient"
target="_blank" moz-do-not-send="true"><img
src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-round-orange-animated-no-repeat-v1.gif"
alt="" style="width: 46px; height: 29px;"
moz-do-not-send="true" width="46" height="29"></a></td>
<td style="width: 470px; padding-top: 17px; color:
#41424e; font-size: 13px; font-family: Arial,
Helvetica, sans-serif; line-height: 18px;">Libre de
virus. <a
href="https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=emailclient"
target="_blank" style="color: #4453ea;"
moz-do-not-send="true">www.avast.com</a> </td>
</tr>
</tbody>
</table>
<a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1"
height="1" moz-do-not-send="true"> </a></div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org" moz-do-not-send="true">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users" moz-do-not-send="true">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
</blockquote>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
</blockquote>
<br>
</body>
</html>