Click here to Skip to main content

C / C++ / MFC

 
AnswerRe: Empty String PinmemberDavidCrow31-Dec-12 6:25 
AnswerRe: Empty String Pinmembermanem21k2-Jan-13 2:26 
GeneralRe: Empty String Pinmemberjeron12-Jan-13 5:21 
GeneralRe: Empty String Pinmembermanem21k2-Jan-13 23:32 
QuestionRe: Empty String PinmvpCPallini2-Jan-13 11:09 
QuestionMFC Grid control 2.27 PinmemberBorisAnimal30-Dec-12 5:46 
AnswerRe: MFC Grid control 2.27 PinmvpRichard MacCutchan30-Dec-12 6:34 
QuestionWhen should printf round a floating number up for display? PinmemberMember 419459328-Dec-12 6:11 
Specifically this statement:
	   printf("Chi square distribution for %s samples is %1.2f (%1.4f), and randomly\n",
	      String_Value, chisq, chisq);
 
I re-implemented this program in MASM to speed it up and I get the following difference (note that I added the (%1.4f)) to display the pre-rounded number to see why I was getting differences:
 
------------------------------------------------------------------ 17
Chi square distribution for 2048 samples is 6.13 (6.1250), and randomly
-------------------------------------------------------------- 17
Chi square distribution for 2048 samples is 6.12 (6.1250), and randomly
 
The question is, which one is correct according to the C spec? Should 6.1250 round up to 6.13 or should it take 6.1250+ to round up?
 
There are other questions such as the following:
           printf("of this %s %s file by %d (%2.2f) percent.\n\n", String_Value, samp,
  	          (short) (((100 * ((binary ? 1 : 8) - ent) / (binary ? 1.0 : 8.0)) + 0.5)),
  	                   ((100 * ((binary ? 1 : 8) - ent) / (binary ? 1.0 : 8.0))));
 
The cast to a (short) seems to truncate a 5.7 to 5, I had to add the (.... + 0.5) just before the cast in order to get the rounded number. Again, I added the (%2.2f) to display the rounding differences.
 
Which is correct according to the C spec, rounding or truncation?
 
The program being re implemented is John Walker's ENT.
 
Dave.
AnswerRe: When should printf round a floating number up for display? PinmvpRichard MacCutchan28-Dec-12 6:53 
GeneralRe: When should printf round a floating number up for display? PinmemberMember 419459328-Dec-12 7:55 
GeneralRe: When should printf round a floating number up for display? PinmvpRichard MacCutchan28-Dec-12 8:01 
GeneralRe: When should printf round a floating number up for display? PinmemberMember 419459328-Dec-12 8:08 
GeneralRe: When should printf round a floating number up for display? PinmvpRichard MacCutchan28-Dec-12 8:18 
GeneralRe: When should printf round a floating number up for display? PinmemberMember 419459328-Dec-12 8:20 
GeneralRe: When should printf round a floating number up for display? PinmemberMember 419459328-Dec-12 9:20 
GeneralRe: When should printf round a floating number up for display? PinmemberMember 419459328-Dec-12 9:58 
AnswerRe: When should printf round a floating number up for display? Pinmemberjschell28-Dec-12 10:45 
GeneralRe: When should printf round a floating number up for display? PinmemberMember 419459328-Dec-12 13:51 
Questiongraphics.h multi-threading problem Pinmemberyudhistira dewanata28-Dec-12 1:22 
AnswerRe: graphics.h multi-threading problem PinmvpRichard MacCutchan28-Dec-12 6:49 
GeneralRe: graphics.h multi-threading problem Pinmemberyudhistira dewanata28-Dec-12 17:23 
GeneralRe: graphics.h multi-threading problem PinmvpRichard MacCutchan29-Dec-12 0:07 
GeneralRe: graphics.h multi-threading problem Pinmemberyudhistira dewanata30-Dec-12 6:01 
AnswerRe: graphics.h multi-threading problem Pinmember Randor 29-Dec-12 9:25 
GeneralRe: graphics.h multi-threading problem PinmvpRichard MacCutchan29-Dec-12 22:28 

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

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


Advertise | Privacy | Mobile
Web01 | 2.8.150123.1 | Last Updated 23 Jan 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid