Click here to Skip to main content
15,897,187 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Example of interface for server Pin
Christian Graus8-Sep-05 17:25
protectorChristian Graus8-Sep-05 17:25 
GeneralRe: Example of interface for server Pin
Member 21610048-Sep-05 20:30
Member 21610048-Sep-05 20:30 
GeneralRe: Example of interface for server Pin
Christian Graus11-Sep-05 11:14
protectorChristian Graus11-Sep-05 11:14 
Questionround a float to int Pin
followait8-Sep-05 15:40
followait8-Sep-05 15:40 
AnswerRe: round a float to int Pin
Christian Graus8-Sep-05 15:44
protectorChristian Graus8-Sep-05 15:44 
GeneralRe: round a float to int Pin
Tim Smith9-Sep-05 3:53
Tim Smith9-Sep-05 3:53 
AnswerRe: round a float to int Pin
Tim Smith9-Sep-05 4:01
Tim Smith9-Sep-05 4:01 
AnswerRe: round a float to int Pin
Tim Smith9-Sep-05 4:26
Tim Smith9-Sep-05 4:26 
Oh dear god, I just realized what they are doing.

(int) (f) does a truncation of the floating point number. In otherwords, it rounds to zero.

2.5 -> 2
0.3 -> 0
-4.5 -> -4

The "(int) (r+0.5f)" trick only works for positive values.

2.3 -> 2
2.7 -> 3
-0.2 -> 0
-0.7 -> 0 (WRONG - should be -1)

By doing 100000.5f, they AVOID (not remove) the negative problem.

Example, but we use 10.5f instead of 100000.5f

-0.2 + 10.5f = 10.3f -> 10 -> 0
-0.7 + 10.5f = 9.8f -> 9 -> -1

But dear god, WHAT A HACK.

The proper way of doing it is:

int i = (int) (r + (r > 0.0f ? 0.5f : -0.5f));

This is why Christian wants people to use math.h because it is easy to create things that sort of work, but often they don't always work.


Tim Smith

I'm going to patent thought. I have yet to see any prior art.
Questionsnmp Pin
sebastianos8-Sep-05 15:31
sebastianos8-Sep-05 15:31 
AnswerRe: snmp Pin
David Crow8-Sep-05 16:32
David Crow8-Sep-05 16:32 
AnswerRe: snmp Pin
ThatsAlok8-Sep-05 21:58
ThatsAlok8-Sep-05 21:58 
QuestionActiveX control container, I really need your help Pin
code_chenyf8-Sep-05 14:41
code_chenyf8-Sep-05 14:41 
QuestionWM_KEYDOWN Pin
Achim Klein8-Sep-05 14:16
Achim Klein8-Sep-05 14:16 
AnswerRe: WM_KEYDOWN Pin
Christian Graus8-Sep-05 14:22
protectorChristian Graus8-Sep-05 14:22 
GeneralRe: WM_KEYDOWN Pin
Achim Klein8-Sep-05 14:37
Achim Klein8-Sep-05 14:37 
GeneralRe: WM_KEYDOWN Pin
Christian Graus8-Sep-05 14:42
protectorChristian Graus8-Sep-05 14:42 
GeneralRe: WM_KEYDOWN Pin
Achim Klein8-Sep-05 14:49
Achim Klein8-Sep-05 14:49 
GeneralRe: WM_KEYDOWN Pin
Christian Graus8-Sep-05 15:12
protectorChristian Graus8-Sep-05 15:12 
GeneralRe: WM_KEYDOWN Pin
Achim Klein8-Sep-05 15:22
Achim Klein8-Sep-05 15:22 
GeneralRe: WM_KEYDOWN Pin
Christian Graus8-Sep-05 15:25
protectorChristian Graus8-Sep-05 15:25 
GeneralRe: WM_KEYDOWN Pin
Eytukan9-Sep-05 2:09
Eytukan9-Sep-05 2:09 
GeneralRe: WM_KEYDOWN Pin
Achim Klein8-Sep-05 14:50
Achim Klein8-Sep-05 14:50 
General[Message Deleted] Pin
Christian Graus8-Sep-05 15:10
protectorChristian Graus8-Sep-05 15:10 
GeneralRe: WM_KEYDOWN Pin
Tim Smith9-Sep-05 4:11
Tim Smith9-Sep-05 4:11 
Question[Msg Deleted Because Of No Reason] Pin
Eytukan9-Sep-05 1:31
Eytukan9-Sep-05 1:31 

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.