Click here to Skip to main content
16,006,065 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: how to change the systen cursor in my program? Pin
Nish Nishant24-Jan-02 22:38
sitebuilderNish Nishant24-Jan-02 22:38 
GeneralMS VC++ 6.0 trouble Pin
24-Jan-02 22:05
suss24-Jan-02 22:05 
GeneralRe: MS VC++ 6.0 trouble Pin
25-Jan-02 2:31
suss25-Jan-02 2:31 
QuestionBug in Vicual C++ or programming mistake ? Pin
24-Jan-02 21:55
suss24-Jan-02 21:55 
AnswerRe: Bug in Vicual C++ or programming mistake ? Pin
Joaquín M López Muñoz24-Jan-02 23:29
Joaquín M López Muñoz24-Jan-02 23:29 
GeneralRe: Bug in Vicual C++ or programming mistake ? Pin
24-Jan-02 23:47
suss24-Jan-02 23:47 
GeneralRe: Bug in Vicual C++ or programming mistake ? Pin
24-Jan-02 23:54
suss24-Jan-02 23:54 
GeneralRe: Bug in Vicual C++ or programming mistake ? Pin
Joaquín M López Muñoz25-Jan-02 2:55
Joaquín M López Muñoz25-Jan-02 2:55 
Oh, I completely misunderstood your first point. Sorry.
There's nothing wrong with your code. The strange behavior is due to rounding errors inherent to floating point arithmetic. These numbers are stored in a internal format like this:

s*mantissa*2^exponent

Where s is the sign (+1 or -1) and mantissa is a number between 1 and 2, with a fixed number of decimals. Due to the limited amount of decimals (binary decimals, to be exact) in mantissa, some numbers that in base 10 have a finite number of decimals can only be approximated by a float or a double. Also, these two types reserve differents amounts of memory for representation: floats are 4 bytes wide and doubles take 8 bytes, so these latter are more precise although this is not always the case --keep on reading.
In your specific case, I've taken a look at the internal representation of h4 and h2 and the exact values are:

h4 =         10690560 * 2^-14 = 652.5
h2 = 5739450696990719 * 2^-43 ~ 652.49999999999988631316227838...

and from this is obvious to deduce why you obtain different results when adding 0.5 and truncating to long.

If you want to know more about floating point arithmetic, do a search on Internet for "IEEE 754" (the standard most microprocessors are based upon for this kind of things).

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
GeneralSame problem in VC5... Pin
25-Jan-02 0:12
suss25-Jan-02 0:12 
AnswerRe: Bug in Vicual C++ or programming mistake ? Pin
rob bakes25-Jan-02 2:11
rob bakes25-Jan-02 2:11 
GeneralMSN Messenger SDK Pin
Ashman24-Jan-02 21:41
Ashman24-Jan-02 21:41 
GeneralRe: MSN Messenger SDK Pin
Michael P Butler24-Jan-02 21:58
Michael P Butler24-Jan-02 21:58 
GeneralDetermine offset m_rectDraw!!! Pin
Eugene Pustovoyt24-Jan-02 21:25
Eugene Pustovoyt24-Jan-02 21:25 
GeneralDlgBar using dlgtemplate Pin
HintiFlo24-Jan-02 21:19
HintiFlo24-Jan-02 21:19 
GeneralRe: DlgBar using dlgtemplate Pin
Fredrik Skog25-Jan-02 2:01
Fredrik Skog25-Jan-02 2:01 
GeneralMoving and Embedded Ms Word Window Pin
Braulio Dez24-Jan-02 21:18
Braulio Dez24-Jan-02 21:18 
Questionwhat about dll application Pin
Gérald Mercet24-Jan-02 21:21
Gérald Mercet24-Jan-02 21:21 
AnswerRe: what about dll application Pin
HintiFlo24-Jan-02 21:38
HintiFlo24-Jan-02 21:38 
GeneralRe: what about dll application Pin
Gérald Mercet24-Jan-02 21:48
Gérald Mercet24-Jan-02 21:48 
GeneralRe: what about dll application Pin
Michael P Butler24-Jan-02 22:00
Michael P Butler24-Jan-02 22:00 
GeneralRe: what about dll application Pin
Gérald Mercet24-Jan-02 23:28
Gérald Mercet24-Jan-02 23:28 
GeneralRe: what about dll application Pin
Michael P Butler25-Jan-02 0:22
Michael P Butler25-Jan-02 0:22 
GeneralRe: what about dll application Pin
Gérald Mercet25-Jan-02 3:14
Gérald Mercet25-Jan-02 3:14 
AnswerRe: what about dll application Pin
Michael P Butler25-Jan-02 0:26
Michael P Butler25-Jan-02 0:26 
GeneralSubClassing Pin
RaviRao24-Jan-02 20:05
RaviRao24-Jan-02 20:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.