Thread: Truncation

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    19

    Truncation

    How is truncation different from loss of precision? They seem like pretty much the same thing to me.

  2. #2
    Registered User
    Join Date
    Sep 2010
    Posts
    46
    Sure, it is loss of precision. But if you think about it, we are losing precision on nearly everything all of the time.

    Why are you worried about it?

  3. #3
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Quote Originally Posted by JSM View Post
    How is truncation different from loss of precision? They seem like pretty much the same thing to me.
    Truncation can give you different results depending on the operation viz., storing an int in a char. Loss of precision on the other hand will give you results in the ballpark.

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by JSM View Post
    How is truncation different from loss of precision? They seem like pretty much the same thing to me.
    Truncation means loss of information. Loss of precision is a matter of informational capacity. For example, if you divide two integers, the remainder is lost. That's truncation. When you reserve a bit in an integer variable to store a boolean value (ie: a flag), that's a loss of precision - instead of, say, 256 possible states you have now only 128; each bit sacrificed cuts the range in half...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    19
    Thanks guys. It was a question on a quiz that I missed.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Loss of precision is the result, truncation is one of the possible causes.
    Rounding is another possible cause.
    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

Similar Threads

  1. Pointer truncation
    By Magos in forum C++ Programming
    Replies: 6
    Last Post: 02-27-2006, 03:26 PM
  2. No truncation?
    By SirCrono6 in forum C++ Programming
    Replies: 6
    Last Post: 02-19-2006, 01:18 AM
  3. weird truncation
    By kristy in forum C Programming
    Replies: 6
    Last Post: 08-06-2003, 04:03 PM
  4. Try out my new game :) !
    By Stan100 in forum Game Programming
    Replies: 10
    Last Post: 06-05-2003, 08:10 AM
  5. Warning message truncation 'double' to 'float'
    By Tojam in forum C Programming
    Replies: 4
    Last Post: 05-01-2002, 02:21 AM