|
I wrote a numerical calculator engine in C++. It can do all the normal arithmetics, it has in-built and user defined variables and functions. The engine compiles with all the compilers I have: Visual Studio 2010 Ultimate and 2012 Ultimate RC, Embarcadero RAD Studio XE and gcc (both on linux and on Windows using mingw). But it does not give me the precision I would like to have.
Example:
Pi is defined in the program as:
3.1415926535897932384626433832795029L
When I convert it to string I got different results (the differences are in italics):
Visual Studio: 3.141592653589793 10000
Rad XE: 3.141592653589793238
gcc: 3.141592653589793238 512808959406186204433
I use long double as the data type, which for Visual Studio is the same as double that is 8 bytes long, for Rad XE it is 10 bytes (80 bits), while for gcc it is 12 bytes (where the last 2 is padding I think). The latter two compilers use the IEEE double sized numbers for long double which is 80 bits long. So the difference in accuracy is understandable.
But the calculator accessory in Windows gives
3.1415926535897932384626433832795
which is almost the same as the insanely large number of digits I entered. It misses the last 3 digits only. This means that
a) the calculator was not compiled with Microsoft compilers
b) or there is some trick which could be used to calculate with higher precision
c) or Microsoft was using some special high / arbitrary precision library
Can somebody help me to find either the tool or the method to achieve this high precision with the compilers I mentioned? Moreover I would like an open source solution, because I want to make the whole code to be open source.
|
|
|
|
|
afalco wrote: c) or Microsoft was using some special high / arbitrary precision library
Yes, the standard IEEE floating point library was replaced with an arbitrary-precision arithmetic library (but that's been a few years back).
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Thanks. Do you know which one?
I was thinking about using one myself but I haven't found a library yet which does not only do arithmetic but also the usual set of functions (sin, etc).
|
|
|
|
|
Some info here[^].
Veni, vidi, vici.
|
|
|
|
|
|
I have a NMS application running in Windows 2003 server. The application usually has a working set of 35.000 KB aprox, but lastly I've seen that the working set climbs slowly until 600.000 KB aprox. or more...
I have revised the too large code with a static analysis tool and I haven't found no suspicious memory leak...
I would like to localize the thread that is consuming a big amount of memory but I don't know how to.
Do you know any aplication that monitors the memory usage of the several threads of a specific process?.
In addition to this, I have found something surprising... Usually I monitor the server by establishing a remote desktop session, when I disconnect the remote desktop session the working set of the application is freed, I mean, It down from 600.000 KB to 30.000 KB..., someone could tell me why?
|
|
|
|
|
If everything else fails to find the memory leak, you can try increasing the memory used ten-fold at single points in your application, one at a time. When you see the working set start to climb ten times faster, you've found the leak. I call this approach the "Signal Flare".
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|
I can recommend using VLD[^] and compile your application in release mode with the define VLD_FORCE_ENABLE.
|
|
|
|
|
There are any number of free and commercial libraries and other tools used to find memory and resource leaks in C++ code.
However you haven't really identified so far that your application has a "leak". What you have identified is that it uses memory. Which of course any application does. A leak is somethere where memory is consumed unintentionally until all memory is gone.
|
|
|
|
|
I use treecontrol to build a tree, it is a 3 level tree has one root node ,there are several children nodes which is under root node, and some leaf nodes are under children nodes,but some are not, they are under root nodes. for each level node I have a popup menu, but for the leaf node which is under the root node, it can't tell which menu it should popup.
In the code I set up a level_num to decide which node popup what kind of menu,but leaf node in the children level,it has same level_num of children node,so could anyone can help?
if(iCode)
{
if(level_num == 4)
m_Menu.LoadMenu( IDR_DELETE_SUBPRJ) ;
if(level_num == 3)
m_Menu.LoadMenu( IDR_ADD_SUBPRJ);
if(level_num == 2)
m_Menu.LoadMenu( IDR_ADD_GROUP);
p_Menu = (CMenu*) m_Menu.GetSubMenu(0);
if( p_Menu != NULL)
p_Menu->TrackPopupMenu( TPM_RIGHTBUTTON|TPM_LEFTALIGN, pos.x, pos.y, this);
p_Menu = NULL;
}
|
|
|
|
|
You could always check the level of the parent node. Alternatively make sure that each node has a level which actually matches its real level in the tree.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
I'v already solved it,I use setItemData to assign a enum variable when I initial the tree nodes, so when I need to decide which menu should be popped up I use getItemData to get that enum variable to decide.
Thank you anyway
|
|
|
|
|
Hi all,
on NM_CLICK i have process the lit item and it takes some time,at this time when i click on the list ctrl whether it disable its working and the click goes in message queue so when 1st click process ends those cilcks automatically perform their action.
i just want to avoid this message queue,
i want no click goes in message queuq while the process is not finish.
please help me how can i do this.
thanks in advance.
|
|
|
|
|
You may disable the list control window while performing time consuming tasks. With disabled windows, mouse and keyboard input is ignored:
CMyListCtrl::OnNMClick(NMHDR * pNMHDR, LRESULT *pResult)
{
CWaitCursor wait;
EnableWindow(0);
EnableWindow(1);
*pResult = 0;
}
|
|
|
|
|
i have already tried this,
but same same situation occur here
while list is disabled ,when click on list control that time the click event not working but after ending of previous process this event work.
|
|
|
|
|
Hi all,
I'm trying to use EnumFontFamiliesEx to get all the fonts on a Windows 7 system, and it only returns one font: "System".
I tried to follow the incomplete documentation for this function here: http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k%28%22WINGDI%2fENUMFONTFAMILIESEX%22%29;k%28ENUMFONTFAMILIESEX%29;k%28DevLang-%22C%2B%2B%22%29;k%28TargetOS-WINDOWS%29&rd=true[^]
but with no luck. Here's my function (in a dialog-based MFC app):
void CAllFontsDlg::fillListBoxWithFonts ()
{
lb = (CListBox*) GetDlgItem (IDC_LIST1);
CDC* pDC = GetDC ();
LOGFONT lf;
lf.lfFaceName[0] = '\0';
lf.lfCharSet = DEFAULT_CHARSET;
HRESULT hr;
hr = EnumFontFamiliesEx (pDC->m_hDC, &lf, EnumFontFamExProc, 0, 0);
}
And here's my callback function (which is called exactly once):
CListBox* lb;
int CALLBACK EnumFontFamExProc(
const LOGFONT *lpelfe,
const TEXTMETRIC *lpntme,
DWORD FontType,
LPARAM lParam)
{
lb->AddString (lpelfe->lfFaceName);
return 0;
}
Can anyone see what I'm doing wrong? Thanks!
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|
Solved my own problem! The "return 0" in the callback function was terminating the enumeration the first time through! My fault...
"Microsoft -- Adding unnecessary complexity to your work since 1987!"
|
|
|
|
|
can any one explain why this code...
#include <boost\logic\tribool.hpp>
using namespace boost;
using namespace std;
tribool test1();
tribool test2();
int _tmain(int argc, _TCHAR* argv[])
{
if( !test1() || !test2() )
cout << "test failed" << endl;
return 0;
}
tribool test1()
{
cout << "test1" << endl;
return true;
}
tribool test2()
{
cout << "test2" << endl;
return false;
}
gives the following output..
test2
test1
test failed
According to the documentation on the || operator the
The operands of logical-AND and logical-OR expressions are evaluated from left to right. If the value of the first operand is sufficient to determine the result of the operation, the second operand is not evaluated. This is called "short-circuit evaluation." There is a sequence point after the first operand. See Sequence Points for more information.
I fixed the "bug" by changing my if statement to
if( !static_cast<bool>(test1()) || !static_cast<bool>(test2()) )
I did notice in the disassembly that the boost function boost::logic::operator|| was being called and wonder if this what was effecting my logic.
Thanks in advance
Thanks,
Robin.
|
|
|
|
|
Unless I'm missing something, the if check should resolve to ( false || true ) which resolves to true and so the test failed should be the output.
Now I see what I was missing.
You are wondering why the call to test2 occurs first? My guess would be that the documentation is only for the intrinsic types of the language and the "tribool" may implement it's own || operator.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Looking further in to the tribool header file there is an overload for the || operator (and && operator) I am yet to look further into it to work out which parameter is which in the overload.
I would of thought that an overridden || operator would or at least should work in the same way as it does with intrinsic types.
Thanks,
Robin.
|
|
|
|
|
The parsing and evaluation of the if construct probably implements some kind of LIFO stack and that is why you see test2 called before test1. But it is odd behaviour.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Wow, that's interesting.
Veni, vidi, vici.
|
|
|
|
|
It is yes and it was very confusing as I had similar code relating to comms where I was doing something like:
if( !unit.Connected() || !unit.IsTypeA()
{
PrintFailMessage( "Failed to connect" );
}
and this worked just fine, but due to other reasons I changed my return type for the functions to boost::tribool and all of a sudden the IsTypeA() function was getting called first. Had me going for ages.
Thanks,
Robin.
|
|
|
|
|
Robin Imrie wrote: all of a sudden the IsTypeA() function was getting called first
Thats a good reason for changing the code to
bool bConnected = unit.Connected();
bool bIsTypeA = unit.IsTypeA();
if ( !bConnected || !bIsTypeA )
{
PinrFailMessage( "Failed to connect" );
}
This will ensure that the call to Connected is always made first, regardless of what type is used for the return value.
Chris Meech
I am Canadian. [heard in a local bar]
In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]
|
|
|
|
|
Hi,
I am using one dll to load an image. I want to apply an effect which exists in another dll. I want to synchronize betwenn these two dlls.
I have one dialog box and one picture control. I'll load an image using FreeImage Dll. Now I an using Magick++ Dll to apply an effect on that Image which is loaded using FreeImage Dll. I am able to do that. I'll take a reference to that instance of loaded image, apply effect using Magick++ dll. My problem is after applying the effect, I have to save the image to some memory location. Again using FreeImage dll to load the effected Image.
I want to apply the effect on the Image using second dll on run time. without saving the image, image should get updated when the user drags the slider.
Please let me know if the above question is not clear.
If understood, any help will be appreciated.
If u have any sample code to synchronize two dlls functionality, it will be of great help.
Regards,
mbatra
|
|
|
|