File:  [MW Coherent from dump] / coherent / b / bin / db_400 / float1.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:36 2019 UTC (7 years, 2 months ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent

/* float1.c - test of floating point */

#include <stdio.h>

#if 0
#define FORCE(var,val)	 {*(int *)(&var) = val;dumpl("FORCE ",var);}
#else
#define FORCE(var,val)
#endif

main()
{
	float x = 1.0, y = 2.0, z;

	xpr(&x);
	dumpl("x = ", x);
	FORCE(x, 0x3F800000);
	xpr(&y);
	dumpl("y = ", y);
	FORCE(y, 0x40000000);
	fflush(stdout);

	z = x + y;
	xpr(&z);
	dumpl("z = ", z);
	FORCE(z, 0x40400000);
	fflush(stdout);

	printf("%f + %f = %f\n", x, y, z);
	printf("that was formatted %%f output\n");
	fflush(stdout);
}

/* Dump a double as 16 hex digits */
dumpl(name,flo,fhi)
char * name;
int flo, fhi;
{
	int exponent;
	int schi;
	char sgn;

	printf("%s%08x,%08x  ", name, fhi, flo);

	sgn = (fhi & 0x80000000) ? '-' : '+';
	exponent = (fhi >> 20) & 0x7FF;
	exponent -= 1023;
	schi = fhi & 0xFFFFF;

	printf("%c1.%05x,%08xx2**%d\n", sgn, schi, flo, exponent);
}

/* dump a float as 8 hex digits - called with address of the float */
xpr(fa)
int * fa;
{
	printf("%08x  ", *fa);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.