Thread: Numerical Search with 1-Bit Precision

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    204

    Numerical Search with 1-Bit Precision

    I'm trying to do a numerical search and I want to find the number exactly. Here is some code to illustrate my question:

    Code:
    long guessed_number, limit_number = 1000001;
    
    guessed_number = (long)(sqrt(my_output_double) * (double)some_long_int / some_double +0.5);
    I want to find the largest value of guessed_number that is not greater than limit_number. I need 1-bit of precision. I'm trying to do a bisection search, but I'm not sure how to maximize the precision. I'm guessing that this must be a classic/standard problem and that references exist, no?

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    You just set your terminating condition to be if( abs(last_guess-current_guess) < 0.5).
    Last edited by King Mir; 01-09-2010 at 12:36 PM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    204
    I think I phrease that poorly. I'm trying to find the largest possible value of my_output_double that results in a value of guessed_number <= limit_number

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    If it's the input variable's precision that you are worried about, then you limit the number of times you loop directly. 1-bit of precision should mean that you do the bisection only once. Of course 1 bit precision is fairly useless. Perhalps you mean integer precision?
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. parent in a binary search tree
    By roaan in forum C Programming
    Replies: 4
    Last Post: 08-26-2009, 07:08 PM
  2. bit value generation doubt
    By roaan in forum C Programming
    Replies: 2
    Last Post: 08-07-2009, 02:23 PM
  3. A Question About Unit Testing
    By Tonto in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2006, 08:22 PM
  4. Having a bit of trouble with a binary search program
    By d-dub in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2006, 05:20 AM
  5. porting application from 32 bit to 64 bit error
    By gandalf_bar in forum Linux Programming
    Replies: 1
    Last Post: 09-14-2005, 09:20 AM