Search:

Type: Posts; User: DoctorBinary

Page 1 of 2 1 2

Search: Search took 0.00 seconds.

  1. Replies
    11
    Views
    1,881

    In this case, since 299792458 is an integer,...

    In this case, since 299792458 is an integer, start out by converting it to binary (Windows Calculator will suffice): 10001110111100111100001001010. That is 29 bits, which is too big; round it to 24...
  2. Replies
    7
    Views
    2,129

    If you're running on Windows (Visual C++), you...

    If you're running on Windows (Visual C++), you can access GMP through MPIR; I've written a "HowTo" at How to Install and Run GMP on Windows Using MPIR - Exploring Binary.
  3. Replies
    4
    Views
    1,716

    Try printf("\r\n %.15f, %s\n",d,buf); or ...

    Try

    printf("\r\n %.15f, %s\n",d,buf);

    or

    printf("\r\n %f, %s\n",d,buf);

    (It won't change the double value, but it will change how it looks when printed.)
  4. Replies
    9
    Views
    1,365

    I know this is the C forum, but if you can use...

    I know this is the C forum, but if you can use C++, GMP has a C++ interface which is much easier to work with. You declare a integer variable like "mpz_class myInt;" and then you can use all the...
  5. Replies
    8
    Views
    5,240

    If you don't understand what powers of two look...

    If you don't understand what powers of two look like in binary you can use a "decimal based" approach. One way is brute force -- simply check the number against all the powers of two that can fit in...
  6. Replies
    5
    Views
    2,227

    You're right, bit fields would work. The tradeoff...

    You're right, bit fields would work. The tradeoff is then bit manipulations vs dependence on endianness.
  7. Replies
    5
    Views
    2,227

    Yes, union is another way to do this. It...

    Yes, union is another way to do this. It essentially does the same thing: it interprets the float storage as an integer. But you'll still need to do the bit manipulations if you want to access the...
  8. Replies
    5
    Views
    2,227

    One way is to cast the floating-point variable to...

    One way is to cast the floating-point variable to an integer and then use integer operations to access the three fields (see IEEE 754-1985 - Wikipedia, the free encyclopedia for how the fields are...
  9. Thread: 2^k

    by DoctorBinary
    Replies
    11
    Views
    1,972

    rakeshkool27, I think we should go back to...

    rakeshkool27,

    I think we should go back to your original "repeated division by 2" idea and make it work. I modified your "check()" function to use modf but without logarithms (don't forget to...
  10. Thread: 2^k

    by DoctorBinary
    Replies
    11
    Views
    1,972

    I don't think a logarithm based solution is going...

    I don't think a logarithm based solution is going to work. First of all, you'd have to choose a smaller EPSILON than you've chosen, to cover a value as large as 2^53-1, for example. On top of that,...
  11. Thread: 2^k

    by DoctorBinary
    Replies
    11
    Views
    1,972

    You are just getting lucky. I ran your program...

    You are just getting lucky. I ran your program using Visual C++ on an Intel machine and looked at the disassembly. Your main call to "check(n)" sets the return value to the contents of the EAX...
  12. Replies
    1
    Views
    2,219

    fmod() is working correctly. What you're seeing...

    fmod() is working correctly. What you're seeing has to do with binary floating-point being an inexact representation of decimal values.

    Let's look at the first parameters to your fmod() calls...
  13. Run this little program to see a difference: ...

    Run this little program to see a difference:


    #include <stdio.h>

    int main (void)
    {
    float f = 0.1f;

    if (f == 0.1)
  14. Replies
    13
    Views
    2,005

    Interesting...so it's being treated like a float...

    Interesting...so it's being treated like a float under the covers!

    Now the rounding you see makes sense. 5617964.354 in pure binary is 10101011011100100101100.01011... This has 23 bits before the...
  15. It's not a coincidence. A binary fraction (i.e. 0...

    It's not a coincidence. A binary fraction (i.e. 0 < f < 1) has as many decimal digits as bits. Try any binary fraction you like. Here are just two examples:

    0.11001111 = 0.80859375...
  16. There are 53 non-zero digits here, which not...

    There are 53 non-zero digits here, which not coincidentally is the number of bits in the significand of a double. In binary, this is '0.' followed by 53 1s:...
  17. Replies
    13
    Views
    2,005

    Can you look at the contents of memory for these...

    Can you look at the contents of memory for these variables -- b in particular? If so, can you post it? (Just post the 8 byte hex value and we can decode it.) That is the surefire way to see what's in...
  18. Replies
    13
    Views
    2,005

    Rounding internally is to binary places; printf...

    Rounding internally is to binary places; printf rounds to decimal places. Try printing 5617964.35400000028312206268310546875 with a format specifier of ".1f" (answer: 5617964.4)



    Those values...
  19. Replies
    13
    Views
    2,005

    The value for b you say you see in the debugger...

    The value for b you say you see in the debugger makes no sense. Even if it were rounded to one decimal place, it still wouldn't be 5617964.5.

    In any case, it's hard to judge what precision you are...
  20. Thread: Binary

    by DoctorBinary
    Replies
    15
    Views
    2,607

    If you want to do it the hard way, why not work...

    If you want to do it the hard way, why not work entirely with strings? You don't have to convert your "numbers" to integers. You could use the binary addition and subtraction rules; for instance,...
  21. Thanks. The bitmasks are just the hex...

    Thanks.

    The bitmasks are just the hex equivalent of binary. So 0x7FF equals 011111111111 in binary; that is, a leading 0 and eleven 1 bits. You set the bits to 1 or 0 depending on how you are...
  22. I've written an article that might help you,...

    I've written an article that might help you, although it's not exactly what you want. I use doubles, though I list modifications to make it work for floats. Also, you should be able to modify it...
  23. Just reverse the number and compare it to itself....

    Just reverse the number and compare it to itself. You can do that using strings, or more elegantly using integers.

    In my article "Finding Numbers That Are Palindromic In Multiple Bases", I have a...
  24. Replies
    13
    Views
    17,511

    I added a "cast" testcase and indeed it ran...

    I added a "cast" testcase and indeed it ran faster than floor (though not a big difference like you saw mike_g). I was using doubles though (with a cast to "long long" to match).
  25. Replies
    13
    Views
    17,511

    I did a quick performance test on Windows (Visual...

    I did a quick performance test on Windows (Visual C++) and, of the three methods -- modf, fmod, and floor -- floor ran faster than modf, and both ran much faster than fmod.

    Of course I don't have...
Results 1 to 25 of 36
Page 1 of 2 1 2