Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: bug sqrt
Replies: 1   Last Post: Jul 18, 1996 2:19 PM

 Messages: [ Previous | Next ]
 Stephane Chauveau Posts: 1 Registered: 12/11/04
bug sqrt
Posted: Jul 18, 1996 6:06 AM

I am running Matlab 4.2c under SUN SOLARIS. There is a bug in the sqrt
function applied to integers. For example

>> sqrt(42)^2
ans =
4.399996948242188e+01
>> sqrt(42.00000001)^2
ans =
4.200000001000001e+01

The following program gives some of the incorrect values:

i=(1:100000)' ;
j=(sqrt(i).^2-i) ;
[I] = find(j>1);
for x=1:size(I)
fprintf(1,'%d %f\n',I(x),j(I(x))) ;
end

>>
42 1.999969
44 1.999969
46 1.999969
56 1.999969
62 1.999969
68 3.999939
80 3.999939
84 3.999939
108 3.999939
112 3.999939
120 3.999939
168 7.999878
176 7.999878
184 7.999878
224 7.999878
248 7.999878
272 15.999756
320 15.999756
336 15.999756
432 15.999756
448 15.999756
480 15.999756
672 31.999512
704 31.999512
736 31.999512
896 31.999512
992 31.999512
1088 63.999023
1280 63.999023
1344 63.999023
1728 63.999023
1792 63.999023
1920 63.999023
2688 127.998047
2816 127.998047
2944 127.998047
3584 127.998047
3968 127.998047
4352 255.996094
5120 255.996094
5376 255.996094
6912 255.996094
7168 255.996094
7680 255.996094
10752 511.992188
11264 511.992188
11776 511.992188
14336 511.992188
15872 511.992188
17408 1023.984375
20480 1023.984375
21504 1023.984375
27648 1023.984375
28672 1023.984375
30720 1023.984375
43008 2047.968750
45056 2047.968750
47104 2047.968750
57344 2047.968750
63488 2047.968750
69632 4095.937500
81920 4095.937500
86016 4095.937500

>

--
Stephane CHAUVEAU.
email : schauvea@irisa.fr
http://www.irisa.fr/prive/schauveau/
Les opinions exprimees dans ce message
n'engagent en aucune facon mon employeur.

Date Subject Author
7/18/96 Stephane Chauveau
7/18/96 Loren Shure