Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- From: "Richard Cooper" <spamandviruses@xxxxxx>
- Date: Sat, 15 Oct 2005 08:57:01 GMT
On Sat, 15 Oct 2005 02:19:23 -0400, ¬a\/b <al@xxx> wrote:
this is false 40 bits hold [log_10(2^40)+1]=13 decimal digits
Nope, I'm right.
no you are wrong [log_10(x)+1] where []="integer part" is how many digits is the number x. For x=2^40 the digits are 13 =[log_10(2^40)+1]
But "how many digits is the number 2^x" isn't the same as "how many digits will x bits hold"...
Look again at what I said:
2^40 = 1099511627776 10^12 = 1000000000000 10^13 = 10000000000000
So, 13 decimal digits are capable of holding more possible values than 40 bits can hold, however, 40 bits can hold slightly more than what 12
decimal places can hold. So I think my answer of 12.04119983 is a little more correct, as 40 bits can hold as many values as 12 decimal digits, plus just a little bit more.
Maybe it's time for another example:
0.0000000000001 (1e-13) in binary is
0.00000000000000000000000000000000000000000001110000100110...
00000000011111111112222222222333333333344444444445555555
123456789012345678901234567890123456789012345678901234560.0000000000002 (2e-13) in binary is
0.00000000000000000000000000000000000000000011100001001100...
00000000011111111112222222222333333333344444444445555555
12345678901234567890123456789012345678901234567890123456Less than 43 bits isn't going to differentiate those two numbers. That's to be expected since log_2(10^13) is 43.18506523, indicating that 44 bits is required for 13-digit decimal numbers.
(Of course, just as 43 bits is enough for these two numbers, 43 bits will differentiate some other 13 digit numbers too, 12% of them actually, the other 88% will share the same binary representation as a neighboring number, just like 1e-13 and 2e-13. You need 44 bits for 100% of the 13 digit numbers to each have a distinct binary representation.)
if i have the decimal number is string format
"-1234568788887877.0000839393948450154454454"
then integer_number=-1234568788887877
i have the fractional part of the number e.g. s ="0.0000839393948450154454454" if r = 839393948450154454454; like big integer the "formula" *seems* to be this:
precision= precision_in_bits_of_fractional_part
(precision) 2 * r Fraction_number = [-------------------------------------] (strlen(s)-2) 10
That's what I said to do, except that you've made twice as much work out of it.
What you're doing is, by ignoring the "0." at the beginning of s, you're multiplying the fractional part by 10 ^ (strlen(s)-2). Then, when you multiply by 2 ^ precision, you shift it left by precision. Then you divide it by 10 ^ (strlen(s)-2), which is the same number that you effectively multiplied it by earlier.
So we've got what you're doing:
1. Seperate number into integer and fraction parts. 2. Convert integer part to binary. 3. Shift integer part left by precision. 4. Convert fraction part to binary as if it were an integer. 5. Shift fraction part left by precision. 6. Divide fraction part by what step 4 effectively multiplied it by. 7. Add or subtract together the integer and fraction parts.
Then there's what I said to do:
1. Convert entire number to binary as if it were an integer. 2. Shift entire number left by precision. 3. Divide number by what step 1 effectively multiplied it by.
Steps 2 and 3 of what you're doing are the same process as steps 4 and 5, so if you just skip step 1 then you get to do them both at the same time, and as an added bonus, you no longer need step 7 to combine the two numbers back together again. So you effectively cut it down to just steps 4, 5, and 6, which make it just like my steps 1, 2 and 3.
You may, however, just want to stick with what you've got, as it may have optimizational benefits depending on the number of bits in the numbers. I'm _still_ not sure what you're doing, so I can't say which way is faster in your particular case, but it depends on wether the divide in step 6 of your method is signifigantly easier than the divide in step 3 of my method.
.
- References:
- Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- From: ¬a\\/b
- Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- From: Richard Cooper
- Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- From: ¬a\\/b
- Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- From: Richard Cooper
- Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- From: ¬a\\/b
- Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- From: Richard Cooper
- Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- From: ¬a\\/b
- Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- From: ¬a\\/b
- Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- From: Richard Cooper
- Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- From: ¬a\\/b
- Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- From: Richard Cooper
- Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- From: ¬a\\/b
- Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- Prev by Date: Re: Performance Monitoring is not bad either
- Next by Date: Re: nasm segment directive
- Previous by thread: Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- Next by thread: Re: Assembly Language - Mathematics WITHOUT maths coprocessor
- Index(es):
Relevant Pages
|