#include<iostream.h> #include<conio.h> template<class abstr> void calc(abstr formal) { cout<<"===\n"; cout<<"for "<<sizeof(formal)<<" bytes"<<endl; abstr intervalx[20]; abstr temp0,temp1,temp2,b; short tempc; abstr x=14.143; abstr xmax=15.051; abstr h=0.242; temp0=13.417; tempc=1; while(temp0<=xmax){ temp2=temp0+h; intervalx[tempc]=temp2; temp0=temp2; tempc++; } b=intervalx[3]; if(x==b) cout<<x<<"="<<b<<endl; else cout<<x<<"!="<<b<<endl; cout<<"===\n"; } void main() { float x1; double x2; calc(x1); calc(x2); cout<<endl; getch(); }
Output:
===
for 4 bytes
14.143!=14.143
===
===
for 8 bytes
14.143=14.143
===
Conclusion: use DLL with 8-byte variable (double)