|
assume
float r=10.3<br />
int i=0; i have the following cases
case 1
i=10;<br />
int y = ceil(r*i) --> Gives 104 , instead of 103 which is my desired value
case 2
i=11 <br />
<code >int y=ceil(r*i) gives 114 which is what I need
say we do this
float x;
x=r*i;
// Codeproject suggestion
<br />
((int)x< ceil (x) )?(int)x:(int)x+1;
case 1 is equated as 103 < 104 ?103:104 which yields 103 , good for me
case 2 is equated as 113<114 ? 113 : 114 which is 113 what I dont need, i need 114
I tried this
float diff = x -(int)x;<br />
int y;<br />
if(diff>0.000000)<br />
y=(int)product;<br />
else <br />
y=(int)product+1;
Code never seems to enter the if case even though diff =0.000000 !
How do i solve this ?
Engineering is the effort !
|
|
|
|
|
act_x wrote:
int y = ceil(r*i) --> Gives 104 , instead of 103 which is my desired value
Perhaps the product of 'r' and 'i' is 103.000001 in memory. Floating-point numbers are not always what they seem.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Floating point is tricky indeed sometimes. What I'd say, is define your "epsilon", which will be the tolerable amount of error in your equations. So let's say the epsilon is .001, then we'll calculate the result like this:
const float fEpsilon = .999;
float y = (int)(x * r + a_fEpsilon); // int cast rounds down
So, for 10 * 10.3 we get about (103.000 + .999) which yeilds 103, and for 11 * 10.3 we get about (103.300 + .999) which yeilds 114.
The trick is to define the epsilon correctly such that (10 * 10.3 + .999) is not represented as greater than or equal to 10.4. You don't want too much precision on it and you don't want too little precision.
Also, .001 here is just a guess that made the results correct in this case, I'm not sure it will work for all other cases.
Chris Richardson
|
|
|
|
|
I'm trying the following with an MFC application (compiled in UNICODE mode, if necessary):
1. Open a local HTML document and read into memory.
2. Do some modifications to the in-memory-document (e.g. replace some strings by other strings).
3. Write the document back to disk.
Now the cavats are: The code should be able to handle documents with different character encodings, e.g. UTF-8, Windows, Cyrillic, Chinese, etc.
Question:
Is anyone aware of methods to detect the encoding and to read in the file from the encoding and convert it to in-memory unicode?
I already looked at http://oss.software.ibm.com/icu/ [^], which can do the loading, but not with auto-detected encoding.
Thanks for your help!
--
- Free Windows-based CMS: www.zeta-software.de/enu/producer/freeware/download.html
- See me: www.magerquark.de
|
|
|
|
|
Why dont you just use IE's DOM ? It can read/write all supported formats. Granted, text manipulation might be a bit trickier, but possible.
Finally moved to Brazil
|
|
|
|
|
|
Good luck. I think you'll have to parse a little of the HTML and figure out the encoding from it by looking at, say the meta charset tag. I doubt you'll find anything aside from a full-blown HTML parser.
That being said, wxWindows[^] does have an HTML view, and they render the HTML themselves. Which means the code you are after is probably in there somewhere.
If your nose runs and your feet smell, then you're built upside down.
|
|
|
|
|
|
|
Hi,
I get the error " Cannot add new member" whenever i try to add a button on control.
what should I do to get rid of it?
Deepak Samuel
|
|
|
|
|
Recheck source code. Maybe you've already added a member variable that corresponds to that particular control and its ID.
Kuphryn
|
|
|
|
|
I had created a "CHAT APPLICATION". Can i change the title name
Client Chat (If no user is logged on and after logged off) to username 's Chat. If username is say X X's Chat
|
|
|
|
|
You need to call SetWindowText from without your app's main window, giving your demanded string as parameter ... in your case the username. This changes the title directly after being called.
We are men. We are different. We have only one word for soap. We do not own candles. We have never seen anything of any value in a craft shop. We do not own magazines full of photographs of celebrities with their clothes on. - Steve
|
|
|
|
|
What MFC architecture is it? Is it SDI?
One solution is UpdateFrameTitleForDocument().
Kuphryn
|
|
|
|
|
kuphryn wrote:
What MFC architecture is it? Is it SDI?
Hi Kuphryn,
Thanks u for ur information. It is SDI.
|
|
|
|
|
Just write your own messagebox.
There are even some articles in codeproject which do the things you want.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Hi,
I'm writing my first full VC++ application and am having problems forcing a redraw. I've added 2 Dialogbars to my app and want to be able to hide and unhide them. I'm doing this via ShowWindow(SW_HIDE) but the dialogbars only update when I resize the whole app window.
I know a little about Invalidate() and InvalidateRect() but I belive they're only for the Client area. RedrawWindow() with the RDW_FRAME|RDWERASENOW flags seems to offer a solution but I can't get this to work either.
Any help for a newbie?
Thanks,
Simon
Multimedia programmer, trying to learn a grown-up language!
|
|
|
|
|
Did you try calling ShowControlBar instead of ShowWindow?
We are men. We are different. We have only one word for soap. We do not own candles. We have never seen anything of any value in a craft shop. We do not own magazines full of photographs of celebrities with their clothes on. - Steve
|
|
|
|
|
Thanks so much Steve - if only I'd posted this question 3 hours ago!
Multimedia programmer, trying to learn a grown-up language!
|
|
|
|
|
How to change the color and title of AfxmessageBox?
Deepak Samuel
|
|
|
|
|
Afaik you can change neither the color nor the title of a message box called by AfxMessageBox(...). You should use CWnd's MessageBox(...) instead, where the title is one of the arguments. But changing the color doesn't work, I'd say you need to write your own message window to do that.
We are men. We are different. We have only one word for soap. We do not own candles. We have never seen anything of any value in a craft shop. We do not own magazines full of photographs of celebrities with their clothes on. - Steve
|
|
|
|
|
AfxMessageBox looks for a string resource with an id of IDS_AFX_IDS_APP_TITLE and uses that for the title if it can be found, otherwise it uses the executable name otherwise. You can't change the colour - that's determined by the user's preferences.
|
|
|
|
|
Sorry, cut & paste error. The resource id should be AFX_IDS_APP_TITLE
|
|
|
|
|
I have a situation where I need to read values from the registry without knowing in advance what values might be there. Can anyone suggest example code to read every value under a particular key ?
Many thanks.
|
|
|
|
|
Hi,
Check out my Registry class.
You can find it on www.xfcpro.com under the "Free Stuff" section, the funtion you want is EnumerateValues().
Feel free to steal the function, use it as a basis for your own or whatever.
regards,
Jonathan
|
|
|
|