|
What version of VC++ are you using? Is this all the relevant code? On VC++ 5.0 your code compiles fine (after adding a missing ';' after long h3 ) and I only get a warning message in the assignment to h4 :
warning C4305: '=' : truncation from 'const double' to 'float'
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Sorry for the missing ";"...
I know the warning... but I'm very surprised it works in VC 5... I use VC6... I'm going to install my old VC 5 to see if I have the right result.
Thanks.
Seb.
|
|
|
|
|
Are we talking about the same thing ? I have no problem to compile this code. What I am searching is why the result is different between the 2 lines (652 != 653)...
|
|
|
|
|
Oh, I completely misunderstood your first point. Sorry.
There's nothing wrong with your code. The strange behavior is due to rounding errors inherent to floating point arithmetic. These numbers are stored in a internal format like this:
s*mantissa*2^exponent
Where s is the sign (+1 or -1) and mantissa is a number between 1 and 2, with a fixed number of decimals. Due to the limited amount of decimals (binary decimals, to be exact) in mantissa, some numbers that in base 10 have a finite number of decimals can only be approximated by a float or a double . Also, these two types reserve differents amounts of memory for representation: float s are 4 bytes wide and double s take 8 bytes, so these latter are more precise although this is not always the case --keep on reading.
In your specific case, I've taken a look at the internal representation of h4 and h2 and the exact values are:
h4 = 10690560 * 2^-14 = 652.5
h2 = 5739450696990719 * 2^-43 ~ 652.49999999999988631316227838...
and from this is obvious to deduce why you obtain different results when adding 0.5 and truncating to long .
If you want to know more about floating point arithmetic, do a search on Internet for "IEEE 754" (the standard most microprocessors are based upon for this kind of things).
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
I have installed a VC 5 : same problem (652 vs 653)
Can you test this :
h4=2.67*100*150/100.0; //float
h3=(long)(h4+0.5); //= 401 ???
h2=2.67*100*150/100.0; //double
h3=(long)(h2+0.5);//= 401 ???
I suspect an error on some type of configuration...
Thank your for your answer...
Seb.
|
|
|
|
|
The double h2=0.5+ (4.35*100*150/100.0); isn't actually 653 but looks like it is
652.9999999999999 , hence the cast truncate returns 652.
printf and the IDE debugger don't show this.
we can see by adding this code
if ((653.0-h2)==0) printf ("equal\n");
also by adding .0000000000001 to h2 before the cast, it then becomes 653 as expected.
The float value must be truncating somewhere and avoiding the rounding error. . (guessing)
|
|
|
|
|
Question: Does this SDK work with MFC?
If so are there any documents? Seems MS make their docs a lil hard to understands hence my lack of success with MSDN
Thanks
Ashman
|
|
|
|
|
The SDK is based around COM interfaces, so yes it will work with MFC/C++/ATL etc?
The only documentation I've seen so far is on the November 2001 platform SDK. I had a quick glance and found it to be a little confusing also. I have an idea for using the SDK but I'm going to have to do some reading first.
Michael
|
|
|
|
|
Hello everybody!
Who may help me with such question
The size pInfo->m_rectDraw always is less than structure CPrintInfo , than the real size of a sheet.
Whether it is possible to determine displacement m_rectDraw from the left top corner of a sheet, if yes, as?
Best regards,
Eugene Pustovoyt
Sonork ID 100.10002:Yaumen
|
|
|
|
|
Can I build a CDialogBAR from an in memory resource, a dlgtemplate?
I prefer memorybased Dialogs then .rc-based one for several reasons and I wanna do so with DialogBars, too. Is it possible?
What do you think about dlgtemplATE-Dialogs at all, any pros or contras?
mfg HintiFlo
|
|
|
|
|
If you leave the .rc .bmp empty you could always add whatever you want from the code. You would still be stuck with the resource though, but that is the way CDialogBar works.
You can also use a CToolBar to add arbitrary controls in. But this also requires a resource. CToolBar provides more control with GetToolBarCtrl(), so if you want to do more advanced stuff, that is probably the way to go.
Cheers,
/Fredrik
Sonork ID: 100.11430:PhatBoy
|
|
|
|
|
Hi,
I´m running word as embedded ( like if it where and standalone application) throught automation, I would like to move and resize the window to a desired position and size ( just to make it fit between my windows), but I got the problem that it seem that Word doesn´t work with pixels ???, do you now something about that ?, How can I convert from pixels to word coordinates in order to move the Ms Word window ?
I use the methods from the application interface:
SetLeft();
Resize();
Thanks, Bye !
Braulio
|
|
|
|
|
I would like to create a vc++ application which could be used from excel. in fact i would like to use the calculation possibilities from c++ and use the environment of excel. I heard that i have to create a dll application, but i never do that before, so i would like to know if anybody could give me a sample of code or indicate me a place where i could find some explanation to do that.
thanks in advance
gerald
|
|
|
|
|
there's an MSDN sample called COMEXCEL, which controls an Excel-programm out of a c++-app. Maybe youcan make it go in the other direction!
good luck!
|
|
|
|
|
i don't want to control excel, i just want to do some calculation with c++ from excel so that i could use the excel environment and benefit of the vc++ compilation
do you see what i mean?
|
|
|
|
|
You'll probably need to create a COM DLL that can be called from Excel VBA via the CreateObject method.
Michael
|
|
|
|
|
could you tell me more about this way of working?
thanks
|
|
|
|
|
It depends on what your are trying to achieve but in theory,
Create an ATL DLL with a Simple COM object, add your methods to the object.
In Excel create your VBA code to call your functions and return your results.
If you need a more detailed answer, you'll need to supply more information about what you want to do.
Michael
|
|
|
|
|
in fact, even i'm not sure if it's possible, i would like to creta a library of functions which could be called from excel or vba, i don't know, so that as i need some array of inputs which are created in excel, i could use the inputs parameters in excel and use c++ methods to do calculations.
is it enough to help me, because it will be very difficult to specify all my application in only few words.
thanks
gerald
|
|
|
|
|
Do a search on MSDN for "Excel COM Add-ins and Automation Add-ins" or do a search for Office COM Add-ins.
Michael
|
|
|
|
|
I've an ActiveX control which displays drawing data.I want to subclass the control.when I execute my dailog based application,the control is subclassed through DDX_Control.Till here everthing is fine.
when I give the control a drawing file to display(through the wrapper function provided for the control),a couple of new windows are created(I checked this in SPY).So the old subclassing in not working and I'm not able to track the messages for the new windows.
How to subclass these new windows???
m_volo.SetSrc(PathName);// This creates additional windows,volo is a
variable of control and SetSrc the wrapper function.
Ravi
|
|
|
|
|
My OS is Win2000 Server.
AddIPAddress(...) or others better?
Shuyi Vi
|
|
|
|
|
I have such a clever little idea for my next mini-project. I know how to make it such that the Scroll Lock light comes on by simulating the pressing of Scroll Lock via SendInput(). BUT.. is there a way to simply turn on the light without bothering with inserting a keystroke into the chain?
I guess these days with Win32 it's not as easy as just poking a low memory address like before.
- Jason
SonorkID: 100.12194
's your uncle
|
|
|
|
|
This link might help you :-
http://www.codeguru.com/system/NTKbdLites.shtml
Nish
Sonork ID 100.9786 voidmain
www.busterboy.org
If you don't find me on CP, I'll be at Bob's HungOut
|
|
|
|
|
Hello.
I got a problem when using vector which is filled in dll. I have a vector of objects, then I pass this address of this vector to the function in a loaded dll. In the dll I'm filling this vector with some values. And problem is that when free dll handler, the memory in the vector got released also, so vector couses an exception when destructors of objects are called.
So it works untill dll FreeLibrary is called.
I've descover that there's no problem when destructor is not decleared as a vertul function. But what if I want to have it virtual?
There's an example of my code:
//It's a simple object:
class CSJImage
{
public:
CSJImage(){};
CSJImage(const CSJImage& orig){};
CSJImage &operator=(const CSJImage& orig){};
// remove virtual and everything is fine,
// but with virtual I have an error if I want to clear the vecor!
virtual ~CSJImage(){};
};
// vector type which address is passed to the dll
typedef std::vector<csjimage> VectorType;
// prototype of function in the dll
typedef int(*fntTest)(VectorType*);
This's function in DLL:
extern "C" __declspec(dllexport)
int Test(VectorType *vec)
{
CSJImage so1,so2;
vec->push_back(so1);
vec->push_back(so2);
return 2;
}
In the main program I'm doing this:
VectorType vec;
HINSTANCE m_hAcqLib;
fntTest fntAddr;
// Load function address into fntAddr here!!!
fntAddr=GetAddress();
fntAddr(&vec);
// Here I can use vec and what it contains
// vec.clear() // this wouldn't couse any exceptions
if(m_hAcqLib!=NULL) FreeLibrary(m_hAcqLib);
// But here I can not any more
vec.clear() // this couses an exception!
Thanks for help
Alexander.
|
|
|
|