C / C++ / MFC
|
|
 |

|
Hi
I want to use this control.
I have VS2008. I create CMyDialog and create CGridCtrl m_Grid as a member. Then I fill grid without problem. I need to take focus cell text when I list grid by arrow down arrow up keys. What I have to do in message map of my class CMyDialog to react on these actions. Can You help me? Where I shoud look in documentation?
|
|
|
|

|
I already answered this question here[^]. Please post in one forum only.
One of these days I'm going to think of a really clever signature.
|
|
|
|

|
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.
|
|
|
|

|
I think the rules for rounding when a floating point's decimal part ends in 5 is, round up if the previous digit is even, and down if it's odd. So 6.125 rounds up to 6.13 but 6.115 would round down to 6.11; this is easy to check. In the second instance if you cast a float to an integer it discards the decimal part.
One of these days I'm going to think of a really clever signature.
|
|
|
|

|
Richard,
Very interesting. I pulled up my 8087 book "THE 8087 PRIMER", John F. Palmer and Steven P. Morse and looked up rounding. The nearest to what you described is the "round to nearest Even" mode, not the round to the nearest Odd as you described. Are you sure about this? Is it in some C spec?
If you are programming the FPU and want to cast a float to an integer, you just execute an FIST or FISTP, which will round to the specified rounding mode which is usually "round to nearest Even" unless you specifically set the mode to "round to 0" before you store the value.
Dave.
|
|
|
|

|
Well I did not have a reference to hand so it's just from what I recall during other development. However, you seem to have more up to date information than me.
One of these days I'm going to think of a really clever signature.
|
|
|
|

|
Richard,
I'm not trying to argue, just trying to find out what the spec says.
"THE 8087 PRIMER" is just a spec, from the Senior Staff Engineers at Intel Corp. explaining why they did what they did. How C uses the hardware should be specified somewhere.
Dave.
|
|
|
|

|
Member 4194593 wrote: I'm not trying to argue I did not mean to imply that you were; I am more than happy to have my assumptions corrected. As to what the C/C++ compiler should do in these cases, you could look at http://www.stroustrup.com/[^], or the Microsoft reference pages[^].
One of these days I'm going to think of a really clever signature.
|
|
|
|

|
Richard,
Thank you for the links. I'll report back with anything I find (if I can understand it).
Dave.
|
|
|
|

|
Richard,
I did find out that a float cast as a (short) is truncated, but not yet found out about rounding in printf.
Dave.
|
|
|
|
 |
|
|
General
News
Suggestion
Question
Bug
Answer
Joke
Rant
Admin