quick log lookup table

This is a discussion on quick log lookup table within the C++ Programming forums, part of the General Programming Boards category; I'm happy that you all had so much fun with this. Imalc: clearly that code is correct and fast, but ...

  1. #16
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    I'm happy that you all had so much fun with this.

    Imalc: clearly that code is correct and fast, but for this project I'd rather stick to a lookup table that can be understood immediately, particularly since it's faster anyway. I was only wondering if there was a nicer syntax to initialize the array. As to "the original code using logs", that was never the original code; I only mentioned it as an example of what I didn't want to do so people wouldn't suggest it.

    phantomotap: I've been meaning to ask you, where did you find that "LL" type suffix? I've never seen that before and can't find it documented anywhere.

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by R.Stiltskin View Post
    I'm happy that you all had so much fun with this.

    Imalc: clearly that code is correct and fast, but for this project I'd rather stick to a lookup table that can be understood immediately, particularly since it's faster anyway. I was only wondering if there was a nicer syntax to initialize the array. As to "the original code using logs", that was never the original code; I only mentioned it as an example of what I didn't want to do so people wouldn't suggest it.

    phantomotap: I've been meaning to ask you, where did you find that "LL" type suffix? I've never seen that before and can't find it documented anywhere.
    LL is "long long", used for 64-bit constants. There is also L, which means "long", but it's rarely used in 32-bit compilers, as long and int are generally the same thing. There are a few others: "U" for "unsigned" and "F" for "float" (as different from "double", so 1.4F is a float constant, 1.4 is a double constant). All can be written as lower or upper case (unusually for C that case doesn't matter), but lower-case l looks very much like a 1, so it's commonly using uppercase.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,261
    Perhaps, I wasn't [...] I imagine.
    True enough, but the binary search variant would probably be faster in any case than the version you posted. Unless the processor had crappy branching in which case it would probably still be the array variant. Unless he was shooting for vectorization which would almost certainly work better with your posted variant. Unless...

    *shrug*

    Yea, I know that the fastest version depends on a lot. I wasn't trying to harp on you or anything for posting a link to the "Bit Twiddling" page. It is a good page to study with or without the need for a fast binary logarithm. I was... let's just say I was giving props to the OP for coming up with a good solution on his own.

    Soma

  4. #19
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    Thanks, it was clear from the context that "long long" is the intended meaning. The "L", "U" and "F" suffixes can be found in K&R and elsewhere but I've never seen "LL" and couldn't find it mentioned anywhere.

    I did finally find it this morning and in the process found a couple of good reference links -- nothing new to some of you but students may want to bookmark these:
    http://www.linuxtopia.org/online_boo...ion/index.html
    http://www.open-std.org/JTC1/SC22/WG...docs/n1256.pdf
    http://msdn.microsoft.com/en-us/libr...k5(VS.80).aspx

  5. #20
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    Quote Originally Posted by phantomotap View Post
    Yea, I know that the fastest version depends on a lot. I wasn't trying to harp on you or anything for posting a link to the "Bit Twiddling" page. It is a good page to study with or without the need for a fast binary logarithm. I was... let's just say I was giving props to the OP for coming up with a good solution on his own.
    'Tis all good.
    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"

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. quick question about log
    By newguy9 in forum C++ Programming
    Replies: 1
    Last Post: 11-22-2008, 02:21 PM
  2. search file for values in lookup table
    By sixstringsgaret in forum C Programming
    Replies: 12
    Last Post: 03-04-2008, 03:23 PM
  3. Lookup table with different spacing between entries
    By Boksha in forum C++ Programming
    Replies: 2
    Last Post: 02-19-2008, 01:40 PM
  4. Writing array, to file
    By zootreeves in forum C Programming
    Replies: 9
    Last Post: 09-08-2007, 05:06 PM
  5. Lookup Table Reference???
    By gvector1 in forum C++ Programming
    Replies: 3
    Last Post: 04-02-2003, 04:03 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21