|
I think you need to spend some more time reading about floating point number representations. A floating point (double) number allows you to store extremely large or extremely small values and anything in between, but at a cost of accuracy in these values. Thus they are no good for applications where numeric accuracy is important, e.g. anything to do with money.
When you display such numbers on screen or printer you have various options for how you wish them to be represented on screen: in scientific 1.3456e-2, or decimal 0.013456 etc.
If you want to use very large numbers with no loss of accuracy then you need to find a library or class (or write one) that can do it for you.
It's time for a new signature.
|
|
|
|
|
Hi all.
I was wondering why a modf ( modulo for float doesn't do its job : I explain)
i have a Big Number X = 1051450100212345678903111694, so as i can't handle it into regular int, _int64, long int i used the double var type.
but the % (modulo) for float is located in cmath by the modf function
so when i want to calculate
double x = 1051450100212345678903111694;
double BigX = 100 * x;
double y = 97;
double z = modf(BigX, & y);
i always have 0 in z
ok why not writing some code doing the regular job.
while (BigX >97)
BigX = BigX - (BigX/97);
ok But in the second code the result will 96.0111 (sth like that) or when i do it with the Calculator of windows it shows me 92 which differs so how could i do such modulo for big numbers ???
Thx U
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
Blood_HaZaRd wrote: i always have 0 in z
That's because there is no fractional part in your value; both x and BigX in your sample are whole numbers. See the description of modf()[^].
It's time for a new signature.
|
|
|
|
|
Thx It seems That i missunderstood The modf . ^^ thx
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
Blood_HaZaRd wrote:
i have a Big Number X = 1051450100212345678903111694, so as i can't handle it into regular int, _int64, long int i used the double var type.
A double cannot handle it with the necessary accuracy, the following code
double x = 1051450100212345678903111694.;
printf("%20f",x);
outputs
1051450100212345700000000000.000000
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You will need to get (or write) a big-integer library. Google will find lots, such as http://mattmccutchen.net/bigint/[^]
Disclaimer: I have nothing to do with Matt, except that I downloaded his library.
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Great Library but could i Use some Commons var, i don't like going for others library :p
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
i 've got errors
error C2258: illegal pure syntax, must be '= 0'
error C2252: 'less' : pure specifier can only be specified for functions
error C2258: illegal pure syntax, must be '= 0'
error C2252: 'equal' : pure specifier can only be specified for functions
error C2258: illegal pure syntax, must be '= 0'
error C2252: 'greater' : pure specifier can only be specified for functions
Just here
class BigInteger {
public:
typedef BigUnsigned::Blk Blk;
typedef BigUnsigned::Index Index;
typedef BigUnsigned::CmpRes CmpRes;
static const CmpRes
less = BigUnsigned::less ,
equal = BigUnsigned::equal ,
greater = BigUnsigned::greater;
enum Sign { negative = -1, zero = 0, positive = 1 };
protected:
Sign sign;
BigUnsigned mag;
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
Looks like you use an old compiler not supporting initialization of static const vars in class declaration. Initialize them in cpp-file instead if BigInteger is your own class.
|
|
|
|
|
lool ok how Unlucky i am
"The Ultimate Limit Is Only Your Imagination."
|
|
|
|
|
I'm a bit confused: 0xE97804B9A34AB4E fits in an __int64 with a nibble to spare. I know it depends what your compiler is and __int64 isn't a standard type but if you've got it and it doesn't need to be portable then why not use it?
Ash
PS: I'm normally against using non-portable code but at least someone trying to compile your code for a platform with a 64 bit int would at least be warned something was up.
PPS: And if you need to store it in 32 bit values you can take advantage of some properties of ints that makes it relatively easy to calculate the modulus.
|
|
|
|
|
Hi All
what is difference between thread priority THREAD_PRIORITY_IDLE,THREAD_PRIORITY_NORMAL,THREAD_PRIORITY_HIGHEST.?We are using like this
AfxBeginThread(ThreadName, (LPVOID) this,THREAD_PRIORITY_HIGHEST,0,0);
How can i check it when application is running?
Please help me
|
|
|
|
|
|
Thanks
Through GetThreadPriority i can know application running with which priority(Like NORMAL,IDLE or HIGHEST).
where i can find theoretical difference?
|
|
|
|
|
|
|
Are you asking what thread priority "actually does"? What it means? What it is for?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
Hi all!
Now I am developing an application to read the disk driver's SerialNumber. I want to read it by WMI. The code is as following:
BOOL CData::GetSerialNumber(BYTE* out)
{
BOOL bRet = FALSE;
HRESULT hr;
hr = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hr))
{
cout << "Failed to initialize COM library. Error code = 0x"
<< hex << hr << endl;
return bRet;
}
hr = CoInitializeSecurity(
NULL,
-1,
NULL,
NULL,
RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE,
NULL);
if (FAILED(hr))
{
cout << "Failed to initialize security. Error code = 0x"
<< hex << hr << endl;
CoUninitialize();
return bRet;
}
IWbemLocator *pLoc = 0;
hr = CoCreateInstance(CLSID_WbemLocator, 0,
CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
if (FAILED(hr))
{
cout << "Failed to create IWbemLocator object. Err code = 0x"
<< hex << hr << endl;
CoUninitialize();
return bRet;
}
IWbemServices *pSvc = 0;
hr = pLoc->ConnectServer(
BSTR(L"ROOT\\CIMV2"),
NULL, NULL, 0, NULL, 0, 0, &pSvc);
if (FAILED(hr))
{
cout << "Could not connect. Error code = 0x"
<< hex << hr << endl;
pLoc->Release();
CoUninitialize();
return bRet;
}
cout << "Connected to WMI" << endl;
HRESULT hres;
hres = CoSetProxyBlanket(pSvc,
RPC_C_AUTHN_WINNT,
RPC_C_AUTHZ_NONE,
NULL,
RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE,
NULL,
EOAC_NONE
);
if (FAILED(hres))
{
cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return bRet;
}
IEnumWbemClassObject* pObj = 0;
IWbemClassObject* pwcObj = 0;
hres = pSvc->ExecQuery(L"WQL",L"select * from Win32_PhysicalMedia",WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,0,
&pObj);
char strID[20];
VARIANT vtData;
CIMTYPE ctType = 0;
long lFavor = 0;
ULONG ulRet;
if(SUCCEEDED(hres))
{
hres = pObj->Next(WBEM_INFINITE,1,&pwcObj,&ulRet);
if(SUCCEEDED(hres) && pwcObj)
{
ZeroMemory(strID,20);
vtData.pbstrVal = 0;
hres = pwcObj->Get(L"SerialNumber",0,&vtData,&ctType,&lFavor);
if(vtData.pbstrVal)
{
CopyMemory(strID,vtData.pbstrVal,20);
}
VariantClear(&vtData);
pwcObj->Release();
bRet = TRUE;
if(SUCCEEDED(hres) && out)
{
CopyMemory(out,strID,20);
}
}
pObj->Release();
}
pSvc->Release();
pLoc->Release();
CoUninitialize();
return bRet;
}
The variable vtData should contain the SerialNumber of the disk driver. But I am always get a value of NULL in vtData. And the return value from
Get(L"SerialNumber",0,&vtData,&ctType,&lFavor); is success. And I try to get some other data in pwcObj. They are all NULL. I don't know the reason. My disk driver is working well. I can get this number by some other software. I hope someone could be kind to tell me the right way. Thx!
There is some white cloud floating on the blue sky. That's the landscape I like.
|
|
|
|
|
Other than strID not being null terminated, your code works fine for me.
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hello, i wanted to get an idea of some basic memory editing so i thought writing a simple trainer for my favorite game would be a good idea.
So i found out how to get the pointer, now when i use cheat engine it gives the correct value if i add the baseaddress + offset.
But if i try that in my program it wont work for some reason.
int offset = 0x804;
int address = 0x818794;
int totalhp = offset + address;
int value;
ReadProcessMemory(hProcess, (LPCVOID)totalhp, &value, sizeof(value), NULL );
std::cout << value << std::endl;
value always returns zero for god knows what reason.
Any idea what iam doing wrong?
|
|
|
|
|
How are you initializing hProcess ?
|
|
|
|
|
The problem is not the handle, the problem is the wrong value i get.
HWND hWnd = FindWindow(0, "AOEII");
if(hWnd == 0)
{
std::cout << "Cant find handle." << std::endl;
_getch();
}
else
{
DWORD proccess_ID;
GetWindowThreadProcessId(hWnd, &proccess_ID);
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, proccess_ID);
if(!hProcess)
{
std::cout << "Cant open process." << std::endl;
_getch();
}
else
{
Readprocessstuff...
|
|
|
|
|
Well found the solution, not exactly sure why i have to do it this way but iam reading about it right now, just thought id post the solution before i forget about it.
int offset = 0x804;
int baseaddress;
int value;
ReadProcessMemory(hProcess, (LPCVOID)0x00818794, (LPVOID)&baseaddress, sizeof(value), NULL );
ReadProcessMemory(hProcess, (LPCVOID)(baseaddress+offset), &value, sizeof(value), NULL );
Thanks for trying to help ![Smile | :)](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
Hello
I want to change the color of text in c(win32 console).
but not entire text only a piece of text that is in the middle.
what can I do?
best regards...
|
|
|
|
|
Look in documents for the console programming API functions. I would but you can do it just as easily as I can and I don't need to.
You can also search for articles on the console here. Most of them use C++ but at least you can see the API functions in action.
|
|
|
|
|