Author |
Topic: Interesting Number (Read 1679 times) |
|
Barukh
Uberpuzzler
Gender:
Posts: 2276
|
|
Re: Interesting Number
« Reply #25 on: Apr 22nd, 2004, 9:03am » |
Quote Modify
|
on Apr 22nd, 2004, 5:54am, towr wrote:Are you sure? It should double the precision afaik.. I've tried it out on all server/computers I have available, and for floats, doubles, long doubles they all give 31, 62, and 72 digits precision repectively. However, they won't all print all of the bits. |
| Are these binary or decimal digits? If binary, then addition for long double is 10 binary ~ 3 decimal digits – as I said. Also, could you please specify what hardware are you using (I mean, the processor). All I said is relevant for X86 processor. on Apr 22nd, 2004, 7:42am, towr wrote: I was looking for something like that – I like to use them in my own programs.
|
|
IP Logged |
|
|
|
asterix
Guest
|
My own figures came from a very old powerbasic program, using "extended precision" 80 bit floating point math. So, roughly how many digits of my answers would have actually been correct?
|
|
IP Logged |
|
|
|
towr
wu::riddles Moderator Uberpuzzler
Some people are average, some are just mean.
Gender:
Posts: 13730
|
|
Re: Interesting Number
« Reply #27 on: Apr 22nd, 2004, 10:19am » |
Quote Modify
|
on Apr 22nd, 2004, 9:03am, Barukh wrote:Are these binary or decimal digits? If binary, then addition for long double is 10 binary ~ 3 decimal digits – as I said. |
| Binary, I thought you meant binary also.. But 3 decimal digits is worth the trouble if you use them right.. Quote:Also, could you please specify what hardware are you using (I mean, the processor). All I said is relevant for X86 processor. |
| I only know what my own computer has, it's a celeron 333MHz. The high performance cluster is probably pentiums, but I don't know about the servers.. (I'd have tried a Cray too, but it doesn' have a C compiler) on Apr 22nd, 2004, 9:51am, asterix wrote:My own figures came from a very old powerbasic program, using "extended precision" 80 bit floating point math. So, roughly how many digits of my answers would have actually been correct? |
| That depends on how you do your calculations. But as 80 bits is about 24 decimals, certainly no more than that. (You can easily loose over half of that precision in certain calculations though)
|
« Last Edit: Apr 22nd, 2004, 10:24am by towr » |
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
asterix
Guest
|
Okay, counting back from the largest intermediate figure I was working with, when n was 6625109, the first digit of my answer required 15 digits of precision, and the error that dropped it below the expected answer showed up at 20 digits of precision.
|
|
IP Logged |
|
|
|
Barukh
Uberpuzzler
Gender:
Posts: 2276
|
|
Re: Interesting Number
« Reply #29 on: Apr 23rd, 2004, 3:47am » |
Quote Modify
|
It seems the discussion has smoothly transitioned into the computational aspect, does it mean everybody is convinced by the theoretical part? on Apr 22nd, 2004, 10:19am, towr wrote:…But as 80 bits is about 24 decimals, certainly no more than that. |
| In fact, it’s less than that. 80 bits is the whole storage for the extended precision double (which I believe is the best is done for long doubles), it comprises of a sign bit, the exponent (15 bits) and mantissa (64 bits). The latter defines the accuracy, that is 19 decimal places guaranteed. For a simple double, exponent is 11, mantissa 53; for a float – 7 and 24 respectively. on Apr 22nd, 2004, 5:54am, towr wrote:To find out how many bits precision they actually used, I took a fraction (1/271) and repeatedly multiplied by two till there was no fractional part left |
| You cannot use this method to determine the precision: when multipying/dividing by 2, the mantissa does not change, only the exponent. The result you get actually depends on the denominator you use (try, for instance, 19 instead of 271). Instead, take a periodic fraction you know the period of, and print as many digits as possible. Here’s what I got for 1/7 (compiled with gcc): float: 0.142857149243354797363281 double: 0.142857142857142849212693 long double: 0.142857142857142857140921 that is, 8, 16 and 20 decimal places.
|
|
IP Logged |
|
|
|
towr
wu::riddles Moderator Uberpuzzler
Some people are average, some are just mean.
Gender:
Posts: 13730
|
|
Re: Interesting Number
« Reply #30 on: Apr 23rd, 2004, 4:01am » |
Quote Modify
|
on Apr 23rd, 2004, 3:47am, Barukh wrote:You cannot use this method to determine the precision: when multipying/dividing by 2, the mantissa does not change, only the exponent. |
| Depends on how you do it. You can easily remove the exponent, and keep the mantissa between 0 and 1, multiply by two, and if it's greater than 1 subtract 1. Repeat till you get zero and you'll know the precision. printing as many digits as you can doesn't work if the compiler won't let you do that..
|
« Last Edit: Apr 23rd, 2004, 4:38am by towr » |
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
Barukh
Uberpuzzler
Gender:
Posts: 2276
|
|
Re: Interesting Number
« Reply #31 on: Apr 23rd, 2004, 6:54am » |
Quote Modify
|
on Apr 23rd, 2004, 4:01am, towr wrote:You can easily remove the exponent, and keep the mantissa between 0 and 1, multiply by two, and if it's greater than 1 subtract 1. Repeat till you get zero and you'll know the precision. |
| In my last post, I described the internal representation of the floating point number (that is, inside the processor). Not only the programmer cannot play with it – even the compiler. That doesn’t mean you cannot make the exponent equal to 0, but that’s certainly not with numbers from the interval (0,1). To make it your way, you need to take the number 2-big_number(1 - 2-another_big_number). Quote:printing as many digits as you can doesn't work if the compiler won't let you do that.. |
| I’ve never seen that compiler won’t let you print. The only two cases I’ve seen were: print the garbage at the end, of print zeros.
|
|
IP Logged |
|
|
|
towr
wu::riddles Moderator Uberpuzzler
Some people are average, some are just mean.
Gender:
Posts: 13730
|
|
Re: Interesting Number
« Reply #32 on: Apr 24th, 2004, 5:29am » |
Quote Modify
|
Look, if my method would work as you say, I'd have gotten a number in the range of 300 (2^10). So obviously it does something right. The one mistake I did make is that if the mantissa doesn't start and end with a 1 (binary) it'll be off a few digits. Here's an example for 4 bits precision mantissa exponent 1xy1 0000 {<1, => *2} 1xy1 0001 {>1, => -1} xy10 0000 {*2} xy10 0001 {-x} y100 0000 {*2} y100 0001 {-y} 1000 0000 {*2} 1000 0001 {-1} 0000 0000 { ==0 } so 4 bits, because we have to repeat the operation 4 times.. Also one of the compilers didn't let me print as many digits as I wanted, so that's not some myth..
|
« Last Edit: Apr 24th, 2004, 5:30am by towr » |
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
|