comparison error

Blitz3D Forums/Blitz3D Programming/comparison error

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

#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)