Added double precision test programs
This commit is contained in:
BIN
src/cmd/9degree/9degree-pc
Executable file
BIN
src/cmd/9degree/9degree-pc
Executable file
Binary file not shown.
57
src/cmd/9degree/9degree-pc.c
Normal file
57
src/cmd/9degree/9degree-pc.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
void print64x( double x ) {
|
||||
char* p;
|
||||
int j;
|
||||
p = (char *) &x;
|
||||
for( j=0; j< sizeof(x); j++) {
|
||||
printf("%02X", p[(sizeof(x)-1)-j]&0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
void print32x( float x ) {
|
||||
char* p;
|
||||
int j;
|
||||
p = (char *) &x;
|
||||
for( j=0; j< sizeof(x); j++) {
|
||||
printf("%02X", p[(sizeof(x)-1)-j]&0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
struct timeval start, stop;
|
||||
volatile double _p64, q64, r64, e64;
|
||||
long i;
|
||||
unsigned long elapsed;
|
||||
|
||||
_p64 = 3.1415926535897932384626433832795;
|
||||
|
||||
for(i=0;i<100;i++) {
|
||||
// 64bit test
|
||||
// 9 degree test input
|
||||
q64 = i;
|
||||
// Convert to radians
|
||||
q64 = q64 * _p64 / 180.0;
|
||||
// Make the test
|
||||
|
||||
gettimeofday(&start, NULL);
|
||||
|
||||
r64 = (asin(acos(atan(tan(cos(sin(q64)))))));
|
||||
|
||||
gettimeofday(&stop, NULL);
|
||||
|
||||
// Convert to degree
|
||||
r64 = r64 * 180.0 / _p64;
|
||||
|
||||
elapsed = stop.tv_usec - start.tv_usec;
|
||||
|
||||
printf("%ld degree 64bit test result= %1.15e time= %lu\n" , i, r64, elapsed );
|
||||
//printf("= 0x");
|
||||
//print64x( r64 );
|
||||
//printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
57
src/cmd/9degree/9degree.c
Normal file
57
src/cmd/9degree/9degree.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
void print64x( double x ) {
|
||||
char* p;
|
||||
int j;
|
||||
p = (char *) &x;
|
||||
for( j=0; j< sizeof(x); j++) {
|
||||
printf("%02X", p[(sizeof(x)-1)-j]&0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
void print32x( float x ) {
|
||||
char* p;
|
||||
int j;
|
||||
p = (char *) &x;
|
||||
for( j=0; j< sizeof(x); j++) {
|
||||
printf("%02X", p[(sizeof(x)-1)-j]&0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
struct timeval start, stop;
|
||||
volatile double _p64, q64, r64, e64;
|
||||
long i;
|
||||
unsigned long elapsed;
|
||||
|
||||
_p64 = 3.1415926535897932384626433832795;
|
||||
|
||||
for(i=0;i<100;i++) {
|
||||
// 64bit test
|
||||
// 9 degree test input
|
||||
q64 = i;
|
||||
// Convert to radians
|
||||
q64 = q64 * _p64 / 180.0;
|
||||
// Make the test
|
||||
|
||||
gettimeofday(&start, NULL);
|
||||
|
||||
r64 = (asin(acos(atan(tan(cos(sin(q64)))))));
|
||||
|
||||
gettimeofday(&stop, NULL);
|
||||
|
||||
// Convert to degree
|
||||
r64 = r64 * 180.0 / _p64;
|
||||
|
||||
elapsed = stop.tv_usec - start.tv_usec;
|
||||
|
||||
printf("%ld degree 64bit test result= %1.15e time= %lu " , i, r64, elapsed );
|
||||
printf("= 0x");
|
||||
print64x( r64 );
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
1
src/cmd/9degree/Makefile
Symbolic link
1
src/cmd/9degree/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../generic.mk
|
||||
@@ -17,7 +17,7 @@ SUBDIR = adb adc-demo ar as awk basic cc chflags chpass \
|
||||
rdprof ranlib re renice retroforth scm setty sl \
|
||||
sed sh smallc smlrc stty sysctl test uname wiznet xargs \
|
||||
zmodem gtest msec unixbench cron compress date2 tip \
|
||||
talloc devupdate uucp smux
|
||||
talloc devupdate uucp smux 9degree mathtest scantest
|
||||
|
||||
# /sbin
|
||||
SUBDIR += chown chroot disktool fsck getty init \
|
||||
|
||||
31
src/cmd/generic.mk
Normal file
31
src/cmd/generic.mk
Normal file
@@ -0,0 +1,31 @@
|
||||
#==========================================
|
||||
# Makefile: makefile for adc-demo
|
||||
# Copyright 2012 Majenko Technolohies
|
||||
# (matt@majenko.co.uk
|
||||
# Last Modified: 29/01/2012
|
||||
#==========================================
|
||||
|
||||
TOPSRC = $(shell cd ../../..; pwd)
|
||||
include $(TOPSRC)/target.mk
|
||||
|
||||
PWD = $(shell pwd)
|
||||
PROG = $(shell basename "$(PWD)")
|
||||
|
||||
OBJS = $(PROG).o
|
||||
SRCS = $(PROG).c
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
-include Makefile.app
|
||||
|
||||
$(PROG): ${OBJS}
|
||||
${CC} ${LDFLAGS} -o $(PROG).elf ${OBJS} ${LIBS}
|
||||
${OBJDUMP} -S $(PROG).elf > $(PROG).dis
|
||||
${SIZE} $(PROG).elf
|
||||
${ELF2AOUT} $(PROG).elf $@
|
||||
|
||||
clean:
|
||||
-rm -f $(PROG) ${OBJS} $(PROG).elf $(PROG).dis
|
||||
|
||||
install: all
|
||||
install $(PROG) $(DESTDIR)/bin/
|
||||
1
src/cmd/mathtest/Makefile
Symbolic link
1
src/cmd/mathtest/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../generic.mk
|
||||
49
src/cmd/mathtest/mathtest.c
Normal file
49
src/cmd/mathtest/mathtest.c
Normal file
@@ -0,0 +1,49 @@
|
||||
// Pito 12/2013
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
// print out double (IEEE 64bit) variable in HEX
|
||||
// ie. 9.0 is 4022000000000000
|
||||
// more on http://babbage.cs.qc.cuny.edu/IEEE-754/
|
||||
|
||||
void print64x( double x ) {
|
||||
const unsigned char* p;
|
||||
int j;
|
||||
p = (unsigned char *) &x;
|
||||
printf("%02X", p[7]);
|
||||
printf("%02X", p[6]);
|
||||
printf("%02X", p[5]);
|
||||
printf("%02X", p[4]);
|
||||
printf("%02X", p[3]);
|
||||
printf("%02X", p[2]);
|
||||
printf("%02X", p[1]);
|
||||
printf("%02X", p[0]);
|
||||
}
|
||||
|
||||
void print32x( float x ) {
|
||||
const char* p;
|
||||
int j;
|
||||
p = (char *) &x;
|
||||
for( j=0; j< sizeof(x); j++) {
|
||||
printf("%02X", p[(sizeof(x)-1)-j]&0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
volatile double num1 = 1.2499999999999998193580478994e-10;
|
||||
volatile double num2 = 2.16000000000000081281633984229e-10;
|
||||
volatile double res = 0;
|
||||
|
||||
res = num1 + num2;
|
||||
|
||||
// print64x(num1);
|
||||
// printf(" + ");
|
||||
// print64x(num2);
|
||||
// printf(" = ");
|
||||
// print64x(res);
|
||||
// printf("\n");
|
||||
|
||||
printf("%1.15e + %1.15e = %1.15e\n", num1, num2, res);
|
||||
return 0;
|
||||
}
|
||||
1
src/cmd/scantest/Makefile
Symbolic link
1
src/cmd/scantest/Makefile
Symbolic link
@@ -0,0 +1 @@
|
||||
../generic.mk
|
||||
84
src/cmd/scantest/scantest.c
Normal file
84
src/cmd/scantest/scantest.c
Normal file
@@ -0,0 +1,84 @@
|
||||
// Pito 12/2013
|
||||
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
// print out double (IEEE 64bit) variable in HEX
|
||||
// ie. 9.0 is 4022000000000000
|
||||
// more on http://babbage.cs.qc.cuny.edu/IEEE-754/
|
||||
|
||||
void print64x( double x ) {
|
||||
const unsigned char* p;
|
||||
int j;
|
||||
p = (unsigned char *) &x;
|
||||
printf("%02X", p[7]);
|
||||
printf("%02X", p[6]);
|
||||
printf("%02X", p[5]);
|
||||
printf("%02X", p[4]);
|
||||
printf("%02X", p[3]);
|
||||
printf("%02X", p[2]);
|
||||
printf("%02X", p[1]);
|
||||
printf("%02X", p[0]);
|
||||
}
|
||||
|
||||
void print32x( float x ) {
|
||||
const char* p;
|
||||
int j;
|
||||
p = (char *) &x;
|
||||
for( j=0; j< sizeof(x); j++) {
|
||||
printf("%02X", p[(sizeof(x)-1)-j]&0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
double num;
|
||||
int i;
|
||||
double sum;
|
||||
FILE *InFile, *OutFile;
|
||||
char str[100];
|
||||
double backup;
|
||||
double result;
|
||||
|
||||
if ((OutFile = fopen("num.dat","w")) == 0) {
|
||||
printf("num.dat not found\n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
for (i=0; i<=10000; i++) {
|
||||
num = 0.0001L * (double)(i);
|
||||
num = num * num * num;
|
||||
fprintf(OutFile, "%1.15e\n", num);
|
||||
}
|
||||
|
||||
fclose(OutFile);
|
||||
|
||||
if ((InFile = fopen("num.dat","r")) == 0) {
|
||||
printf("num.dat not found\n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
sum = 0;
|
||||
num = 0;
|
||||
|
||||
for (i=0; i<=10000; i++) {
|
||||
backup = sum;
|
||||
fgets (str, 80, InFile);
|
||||
sscanf (str,"%le",&num);
|
||||
result = sum + num;
|
||||
|
||||
if (sum != backup) {
|
||||
printf("*** SUM CHANGED: %1.15e => %1.15e ***\n", backup, sum);
|
||||
}
|
||||
sum = result;
|
||||
}
|
||||
|
||||
printf("Sum test result = %1.15e\n", sum);
|
||||
printf("Shall be result = 2.500500025000002e+03\n");
|
||||
printf("Sum test result (HEX) = ");
|
||||
print64x( sum );
|
||||
printf("\n");
|
||||
printf("Shall be result (HEX) = 40A389000346DC62\n");
|
||||
|
||||
fclose(InFile);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user