Thread: Anyone see a better way of doing this

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    104

    Anyone see a better way of doing this

    I have a list of possible exposure values, which I need to compare with the calculated value, and choose the closest one.

    Code:
    // This finds closest match
    If 0<exposure<0.00025
    Then  Output "Closest exposure value is 1/4000"
    Else If 0.00025<exposure<0.0005
    Then Output "Closest exposure value is 1/2000"
    Else If 0.0005<exposure<0.001
    Then Output ""Closest exposure value is 1/1000"
    ...
    This is quite tedious as there are 20 values or so to compare with . Does someone see a better way of doing this ?

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    make an array of limit values and use the loop

    also note that
    If 0<exposure<0.00025
    is not a C
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    104
    Yep , it's just pseudocode I need to make for now

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by ICool View Post
    Does someone see a better way of doing this ?
    You could use log to calculate the table starting point in O(1) time.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed