|
Exactly what is telling you those values ?
I am willing to bet that if you look at the 8-byte binary value they will be identical. It is the output display that is the only thing that differs. If you use a format specifier of "%.2f" with one of the printf family of functions (print, sprintf, or fprintf) I expect that you will see 1.15.
It is important to note that it is virtually impossible to acquire exactly accurate floating point values. There are nearly always rounding errors involved that you must just deal with.
__________________________________________
a two cent stamp short of going postal.
|
|
|
|
|
Thanks for your reply
I was getting the values from the quick-watch window displayed by the debugger. The 8-byte binary value displayed in the memory window IS the same.
I have found that the real cause of my bug is the use of the pow() function from math.h.
I had code like
long rounding = 4;
double result = pow(10, -rounding);
which in vs6 returns result = 0.0001
and in vs2003 returns result = 0.0
these values ARE different in memory
Looking at math.h I think the code above was calling
long pow(long, long) resulting in 0 and auto casting the result to a double.
I changed it to
double result = pow(10.0, -rounding);
and now it works. Why its different in vs6 and vs2003 I dont know
|
|
|
|
|
As previously mentioned you should not expect an exact comparision when working with floating point numbers. To check equality you need to compare the differnce to epsilon. If the difference is < or = epsilon then the numbers are equal. Otherwise they are not.
This is done as follows: take the absolute value of the difference of the absolute values of the two floating point numbers and compare the result to epsilon. If the difference is less than or equal epsilon then the numbers are equal.
if( FLT_EPSILON =< fabsf( fabsf(f1) - fabsf(f2) ) )
printf( "numbers are equal\n" );
else
printf( "numbers are not equal\n" );
NOTE: there are double precision variants of epsilon and fabsf.
Sam
Sam
|
|
|
|
|
Hi,
My VC++ solution has 10 projects with 40 .rc files. I want to assign unique ID's to the ID's in resource.h files as there are many duplicates. So got a ResOrg.Net tool. I ran this tool which generated unique numbers for the IDs. But my application is not launching, something went wrong. I don't know what??
Can anybody help.
Also I want to allot some range ID's for all the projects.
eg. Proj 1 -> 1 - 1000
Proj 2 -> 1001 - 2000
etc....
Will there be a problem if I try alloting the ID's in this manner?
Thanks,
Prashant
|
|
|
|
|
When I have a lot of projects, I start redifining range of IDS at the bottom of the H file. All goes OK.
Jaime
|
|
|
|
|
Jaime,
The problem arises when the numerical value used by the IDS/any control is the same as some other control in another project.
At run time, the wrong string/control would be used. So for this we have to have unique ID's across all projects correct? So I am doing the cleanup, please help me out on some tools/documents available on net if any..
Thanks,
Prashant
|
|
|
|
|
I told you that I start redifining all range ID's. That way, all ID's become unique for all projects so I never have problems with that.
Since I know about that problem, I modify the ranges when I create the projects. Sorry, but I don't know any tool that does it automatically when the projects are already created.
If the application didn't launch after your modification, you only have to debug it. That's the solution to find what ID was the problem.
Jaime
|
|
|
|
|
Ok this is my source:
-----------------------------------------------------
void CTycoonDlg::OnList()
{
//Displays changes...
extern CListBox* OnList;
// Set the first visible item in the list box to be the middle item
OnList->SetTopIndex(OnList->GetCount()/2);
}
-----------------------------------------------------
I put the code inbetween it just there, and now I can't compile it...
OnList is a list box, and when I try to compile it I get this error...
--------------------Configuration: Tycoon - Win32 Debug--------------------
Compiling...
TycoonDlg.cpp
Linking...
TycoonDlg.obj : error LNK2001: unresolved external symbol "class CListBox * OnList" (?OnList@@3PAVCListBox@@A)
Debug/Tycoon.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
Tycoon.exe - 2 error(s), 0 warning(s)
Any Ideas?
I'm not that good at debugging errors.
Anyways, please keep it simple, I don't really understand much to MFC, im new to it.
I know a bit to C++.
|
|
|
|
|
extern CListBox* OnList tells the compiler "there's a variable called OnList with type CListBox* that is declared in some other source file". Have you declared OnList in some other file? If not, it should probably be a local variable and you need to initialize the pointer before using it.
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
You cannot stop me with paramecium alone!
|
|
|
|
|
Hello,
I am using of
CDaoDatabase CDaoRecordset Classes and I want to know that How can I use SQL Commands by them?
Like this(I want to have filter)
"select * from Name where name='something'"
and How can I Set a Field to an Edit Object?
Best Wishes,
Thanks.
|
|
|
|
|
the follwing piece of code might help you...
CDaodatabase database;
database.Create("C:\sample_log.mdb");
CString SqlCmd = "CREATE TABLE list (NAME VARCHAR(20), AGE INT, DATE VARCHAR(20), TIME VARCHAR(20));";
database.Execute(SqlCmd);
database.Close();
now to search....
build a query string and execute it...
CString query = "Select * from list where NAME='ABCD'"
CDaoDatabase db;
db.Open("C:\sample_log.mdb");
CDaoRecordSet record(&db);
record.Open(AFX_DAO_USE_DEFAULT_TYPE,query,0);
Then...
while(!recor.IsEOF())
{
.....
use GetFieldValue() for each record in the recordset
}
record.Close();
db.Close();
|
|
|
|
|
hi i want to be able to create folders programaticly
also i want to be able to delete files programiticly
i also need to be able to access a folder and loop through each file in the folder
can someone give me some tips or show me where to look
Thanks
|
|
|
|
|
|
how did you get the text and underline to be differnt colors !
Bikram Singh
|
|
|
|
|
|
It works !
Bikram Singh
|
|
|
|
|
thanks for your time in advance
i programming small video application
i use directdraw to render video frames directly
first i set Surface pixel format to RGB format,
GetDC(&_hdc) worked fine, so i could overlay some text on the screen
but when i changed Surface's RGB pixel format to YUV, problem came out..
video rendering works fine, but GetDC(&_hdc) function failed...
Returned error code is just 0x88760249 (Can't Create DC).
it answers me nothing except it's just failed.
<br />
..<br />
HRESULT res = _surface->GetDC (&_hdc);
..<br />
what might be the cause of this error??
here's some code snippet,,setting pixel format
<br />
...<br />
_srfDesc.dwFlags |= (DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT);<br />
_srfDesc.dwWidth = width;<br />
_srfDesc.dwHeight = height; <br />
_srfDesc.ddpfPixelFormat.dwSize = sizeof(DDPIXELFORMAT);<br />
_srfDesc.ddpfPixelFormat.dwFlags = DDPF_FOURCC;<br />
_srfDesc.ddpfPixelFormat.dwFourCC = MAKEFOURCC('Y', 'V', '1','2');<br />
..<br />
thanks again and
prompt reply would be appreciated!
|
|
|
|
|
baboguru wrote:
what might be the cause of this error??
Simple. GDI doesn't support YUV pixel formats; it supports RGB only
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
So simple~
thanks you very much Ryan,
Ryan,, i have one more question(i hope its anwser is simple too.. )
Is there any ways to overlay texts on the OffScreenSurface(video buffer)
of which pixel format is YUV, not RGB? or is it possible anyhow?
thanks again
|
|
|
|
|
baboguru wrote:
Is there any ways to overlay texts on the OffScreenSurface(video buffer)
of which pixel format is YUV, not RGB?
You can get a pointer to the raw image data in memory, which you can write to however you like. There are libraries out there which can abstract this into pixels for various pixel formats (AntiGrain Geometry[^] comes to mind), or you can work out the data yourself. But there are no Windows calls to do it for you.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Thank you Ryan~~ now i know what to do
thank you again
|
|
|
|
|
Anyone know of a class for the common dialog Select Folder i cant seem to find one for MFC,
|
|
|
|
|
|
|
i just want to know how to add the letters after a number automaticly like 1st 2nd 3rd 4th 5th the numbers will change day to day
|
|
|
|