Re: Reading specific memory address into variable

From: David Casey (sgtcasey_at_IH8SPAMcableone.net)
Date: 10/20/04


Date: Tue, 19 Oct 2004 23:44:58 -0600

On Tue, 19 Oct 2004 21:26:51 -0700, Gianni Mariani wrote in
<news:PZOdnb9TpMCTdOjcRVn-3w@speakeasy.net>:

[snip!]

> When exp is at the limits of what the double can store, the mantissa is
> not normalized, so you can simply call frexp twice and compare the
> exponents to be equal both times. Then you can subtract the 2 resulting
> mantissas and call std::frexp on the result and the exponent on the
> third call will be the negative of the number of significant binary
> digits which you can convert to decimal by the siggestion I made earlier.

I hadn't thought of using stuff like that, but I have found a way which
works great and is about as simple as you can get.

Okay, the variables I'm comparing are a constant which in my program I call
cons_pi and it equals 3.14159265358979. The user enters an integer number
for how many times they want to do that calculation to figure out pi (4/1 -
4/3 + 4/5 - 4/7 etc.). That calculation is placed into calc_pi. Both
these numbers are long doubles to get as many decimal places as I can.

Anyway, the teacher wants us to figure the accuracy of our calculated value
which is where I was stuck trying to figure out a way to compare the two
numeric values.

Well, I decided to multiply each value starting with 10 and then comparing
the int() of each of the variables. If the variables are equal then that
is one position of accuracy and the do-while loop continues while
incrementing the accuracy variable by 1 and incrementing the multiply
variable times 10. If the variables are not equal then there is no more
accuracy possible with the calculated value so flag is set to on and the
do-while loop ends returning the accuracy variable to main().

I just ran from 1 to 50 one-by-one and then various values up to
100,000,000 and it works great. After I clean up the code and give it the
once over again I'll set the program to run through 2,147,483,647 and head
off to bed. Maybe it will be done in the morning when I get up to go to
class. ;-)

It seems I was trying a bit too hard looking for a difficult method to get
the job done with it really ended up being a heck of a lot easier.

Dave
Now I can get to sleep. :-)

--
You can talk about us, but you can't talk without us!
US Army Signal Corps!!
http://www.geocities.com/davidcasey98
Remove IH8SPAM to reply by email!


Relevant Pages

  • Re: Help! Need to sorted collection accessible by key
    ... Equals() and GetHashCode, then return the hashcode of the key you want ... access with, and compare by the one you want to order by, and put it ... If two items that compare equal using the _hasher key do not compare ... hash to the same bucket in the hash table but will not be equal to ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Interesting list Validity (True/False)
    ... Python to compare those strings equal. ... "a equals d" is true. ... There may or may not be any coercion involved.) ... And if you ask any mathematician, he'll say that is equal to. ...
    (comp.lang.python)
  • Re: do I need to override the equals() method?
    ... Make sure they are consistent with each other, i.e., if two instances compare equal, they must have the same hash code. ... It occurs to me that something I'd like in an IDE is for it to let me mark the fields that consititute my unique key, and then it can generate equals() and hashCode(). ... lists the local variables with check boxes, and also gives an option to ...
    (comp.lang.java.programmer)
  • Re: Interesting list Validity (True/False)
    ... The exceptions you mean are not exceptions to "'X==Y' means 'X equals ... "Obbjects of different types never compare equal". ... The exceptions being different numeric types and different string types, that have a special treatment; see section 5.9 in the Reference Manual for details." ...
    (comp.lang.python)
  • Re: Custom fields and internal values
    ... calculation. ... that reads [Duration], I can see a 4 day duration task is shown as ... How did the person know to compare Baseline finish to 10000? ... How is MS Project storing this? ...
    (microsoft.public.project)