J
Jorge
The function you observed, Resol, is now Resol1; new Resol3 is similar
but uses only randoms >= 0.5.
John,
I have retouched your resol1() a little bit. Now it receives a
parameter p, and it doesn't return until the higher resolution found
remains unchanged for p iterations of the loop. It gives higher
readings now.
I have also written a bits() function that finds what is the smaller
power of 2 for which it's true that (2^x) === ((2^x)+1). I think that
that must be the size of the mantissa, or not ?
See it here : http://tinyurl.com/68d9br
These are the numbers I get :
IE 5.2.3 : 53, 53.
FF2, FF3 : 52, 53.
Safari : 30, 53.
Opera 9.51 : 31, 53.
iCab 3.0.5 : 63, 53.
But I don't understand why those numbers are different. And, if the
mantissa is 53 bits (iCab), how can, why does resol1() give 63 ?
Here's the code :
<script>
window.onload= function () {
var resol1= (function (p) {
var x, t, max= 0, i= p;
while (i) {
t= 0, x= Math.random();
while ((x*= 2)%1 > 0) { // shift left until empty
t++;
}
if (t > max) {
max= t, i= p;
} else {
i--;
}
}
return max;
})(1e4);
var bits= (function () {
var x, i= 0;
do {
x= Math.pow(2,++i);
} while (x !== (x+1))
return i;
})();
var test= Math.pow(2,bits);
var text= "resol1() : Maximum resolution is at least "+resol1+"
bits.<br>";
text+= "bits() : "+bits+" -> In this browser "+(test+1)+" ===
1+"+test;
(document.body.appendChild(
document.createElement(
'h2'))).innerHTML= text;
};
</script>
Thanks,
--Jorge.