|
Hi Guys,
I'm having a heck of a time doing some rounding here, hoping someone has a quick solution.
Example:
CHAR string[xx] = "1.019", null terminated string holding the current release.
FLOAT instver, intended to hold the float value of string ( I want it to be 1.019 )
When I do:
sscanf ( string, "%5lf", &instver );
My result is always: 1.0189999
I've tried:
instver = atof ( string );
And I still get the same results. I've done some peeking around the helpfile, can't find anything that will let me truncate/round the decimal spots.
Anybody?
Thx.
Mike.
|
|
|
|
|
You are always going to get this degradation of floating point accuracy. You need to read up on how floats are stored in IEEE 754 specification.
Floats are stored as a binary value that is composed of the mantissa and the exponent just like in regular scientific notation, however they are binary, so you are converting a decimal format into binary - this is going to cause round-off error.
It is still basicly fairly accurate. If it is just a cosmetic thing you can use format statements and they will round to the correct value for you. printf("%.3f", val); will do this.
J.
----------------------------
|
|
|
|
|
I'm trying to find "Exact Analysis of Merge sort"- M.Golin & R.Sedgewich - Fourth SIAM Conference on Discrete Mathmatics for my assignment. Could you show me where to find it or if you got it, please send to my email
azury_thanh@yahoo.com
Thank you so much
Study is suffering!!
|
|
|
|
|
merge sort can be implemented in various ways but a very good way to do it is to use the Divide and Conquer Algo.
it divides the array into two.. then sorst the two seperately and then finally merge them back to get the final sorted one.
we use recursive divide calls to divide the array till we get the array with 2 or 1 element.
it runs in time O(n ln n)
if u need the code and the detailed analysis how to derive the complexity.. then mail me.
hope this satisfies u
Deepesh Dhakad
Indian Institute of Information Technology,Allahabad
India
|
|
|
|
|
I have created a lsitbox control, and got a database into MFC application. i am trying to display data from a particular field into the listbox.when i did this
CListBox* pListBox = static_cast<clistbox*> (GetDlgItem(IDC_COURSE));
pListBox->AddString(m_pSet->m_Course);
it is only showing the first one. how can i make display all, and let me choose from it.please let me know
|
|
|
|
|
swerajan wrote:
pListBox->AddString(m_pSet->m_Course);
it is only showing the first one. how can i make display all,
How about a loop?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
One solution is InsertItem().
Kuphryn
|
|
|
|
|
Which would be for a list control, would it not?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
how to convert LPCOLESTR to CString and viceversa ?
|
|
|
|
|
|
Hi!
I have a dialog based project.
The first dialog is the login, the second the menu.
When I exit from the login (cancel), my thread exits with code 0.
But when I exit from the menu, I close my menu dialog with cancel, and automaticaly my login dialog with CDialog::OnOK(), and the thread exits with code 13.
I don't know where is my bug...
Thanks
|
|
|
|
|
Thread exit codes can be whatever you want. The fact that it's non-zero doesn't necessarily indicate an error, and in fact the return code of the main thread of a GUI app is generally not useful.
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | RightClick-Encrypt | 1ClickPicGrabber
"That probably would've sounded more commanding if I wasn't wearing my yummy sushi pajamas."
-- Buffy
|
|
|
|
|
Hi,
I've subclassed a an edit control from CEdit.
below is what's in the header file:
class CMyEdit: public CEdit<br />
{<br />
public:<br />
void ChangeColour(const unsigned long &bg, const unsigned long &fg);<br />
protected:<br />
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);<br />
<br />
DECLARE_MESSAGE_MAP()<br />
private:<br />
CBrush m_brush;<br />
unsigned long TextColour;<br />
unsigned long BKColour;<br />
CFont m_TextFont;<br />
};<br />
<br />
}<br />
the methods in my C++ files are:
HBRUSH CMyEdit::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) <br />
{<br />
HBRUSH hbr = CEdit::OnCtlColor(pDC, pWnd, nCtlColor);<br />
<br />
pDC->SetTextColor(TextColour);<br />
<br />
return m_brush;<br />
}<br />
<br />
void CMyEdit::ChangeColour(const unsigned long &fg, const unsigned long &bg)<br />
{<br />
TextColour = fg;<br />
BKColour = bg;<br />
m_brush.DeleteObject();<br />
m_brush.CreateSolidBrush(BKColour);<br />
Invalidate();<br />
My problem is why the method OnCtlColor is NOT being called?
Any explanations
Thanks, Alton
|
|
|
|
|
Have you set a reflection mapping up (ON_WM_CTLCOLOR_REFLECT) in the class's message map?
Steve S
|
|
|
|
|
In my Cdialog based class, I have three buttons arranged vertically and centered in the dialog at design time. I dont do anything special to the class when I run it. It shows up with the right side of the dialog larger than the left side, i.e. the buttons are no longer horizontally centered. I can I guess do a runtime positioning with MoveWindow etc but am wondering why this is happening. ANything short of runtime positioning I can do at designtime to fix this?
Thanks,
ns
|
|
|
|
|
ns wrote:
It shows up with the right side of the dialog larger than the left side,
That shouldn't happen. Windows won't move/align your controls by itself.
/ravi
Let's put "civil" back in "civilization"
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
DragAcceptFiles is basically a legacy API - this is how Windows 3.1 File Manager used to indicate a file drop onto an application.
Explorer uses the full OLE drag-and-drop protocol. See Transferring Shell Objects with Drag-and-Drop and the Clipboard[^] for some basic information and pointers on how to register for OLE drag-and-drop.
|
|
|
|
|
To start my internal net is 100mbit.
I need to read a lot of data ( couple of Gigs ) over the net very frequently.
So I need a program that copies the data and I want to go as fast as possible.
If I copy the files over FTP I get over 10MB/s in transfer speed and task manager shows network usage at 98-99% witch is really great. But I don’t want to use FTP.
I want to read the file from a network share.
And if I do, I only get like 6.5MB/sec so I made my test program to read/write threaded.
Triple buffers and read/write at the same time and stuff. And now I get like 7-7.5 MB (not much of a performance gain)
Anyway network usage only gets up to about 56-59% if I read from network share. I tried reading with different chunk sizes but did not make any difference.
If I copy the file with windows drag'n'drop I get also low speed but a little better, network usage of 62%
I understand that doing a lot of readfile(...) and stuff will generate more io request then receiving data over FTP. But should it really drop so much.
Anyone have any idea of why I can’t get close to 100% network usage when reading from a network share?
/Mathias
|
|
|
|
|
The problem depends on the design and implementation of the actual application.
Kuphryn
|
|
|
|
|
Hi.
The callback function is called when it receives some data. But it receives huge amount of data that requires a lot of time to copy. So I want to put this function to some thread. How to do this? I tried to inherit some class from CWinThread :
class MyThread : public CWinThread
{
.....
void SomeCallBack(...);
}
then MyThread m* = new MyThread; m->CreateThread();
but the thread creates and then completed. Why?
How to solwe my problem(how to create thread class that finished existence when I need)? Please, send example if it is possible.
Thankful in advance.
|
|
|
|
|
snmail wrote:
but the thread creates and then completed. Why?
Does the newly created thread do anything? Just curious, but why aren't you using AfxBeginThread() ?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
There are several solutions including AfxBeginThread() and __beginthreadex(). Post the code in the thread. I suspect that the thread callback function does nothing and just returns.
Kuphryn
|
|
|
|
|
Is there a tool/software that will parse my existing C++ classes and produce a diagram (drawing) of the class/objects hierarchy?
|
|
|
|
|
UML Studio from http://www.pragsoft.com/ is actually quite good. You are allowed to evaluate it before registering/paying too. However if I had VC7 with everything then I would use Visio.
|
|
|
|
|
Visio does, but it's not free
|
|
|
|