summaryrefslogtreecommitdiff
path: root/fourier.c
diff options
context:
space:
mode:
Diffstat (limited to 'fourier.c')
-rw-r--r--fourier.c60
1 files changed, 28 insertions, 32 deletions
diff --git a/fourier.c b/fourier.c
index 4ce1153..5596e7a 100644
--- a/fourier.c
+++ b/fourier.c
@@ -1,9 +1,10 @@
-/*
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
-#include <strings.h>*/
#include <math.h>
+#include <limits.h>
+
#include "nmglobal.h"
#include "nbench1.h"
@@ -34,11 +35,11 @@ static double thefunction(double x,
void DoFourier(void)
{
FourierStruct *locfourierstruct; /* Local fourier struct */
-double *abase; /* Base of A[] coefficients array */
-double *bbase; /* Base of B[] coefficients array */
+double *abase = NULL; /* Base of A[] coefficients array */
+double *bbase = NULL; /* Base of B[] coefficients array */
unsigned long accumtime; /* Accumulated time in ticks */
double iterations; /* # of iterations */
-char *errorcontext; /* Error context string pointer */
+char *context; /* Error context string pointer */
int systemerror; /* For error code */
/*
@@ -49,7 +50,7 @@ locfourierstruct=&global_fourierstruct;
/*
** Set error context string
*/
-errorcontext="FPU:Transcendental";
+context="FPU:Transcendental";
/*
** See if we need to do self-adjustment code.
@@ -59,21 +60,18 @@ if(locfourierstruct->adjust==0)
locfourierstruct->arraysize=100L; /* Start at 100 elements */
while(1)
{
-
- abase=(double *)AllocateMemory(locfourierstruct->arraysize*sizeof(double),
- &systemerror);
- if(systemerror)
- { ReportError(errorcontext,systemerror);
- ErrorExit();
+ abase = realloc(abase, locfourierstruct->arraysize * sizeof(double));
+ if (!abase) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ exit(1);
}
- bbase=(double *)AllocateMemory(locfourierstruct->arraysize*sizeof(double),
- &systemerror);
- if(systemerror)
- { ReportError(errorcontext,systemerror);
- FreeMemory((void *)abase,&systemerror);
- ErrorExit();
- }
+ bbase = realloc(bbase, locfourierstruct->arraysize * sizeof(double));
+ if (!bbase) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ free(abase);
+ exit(1);
+ }
/*
** Do an iteration of the tests. If the elapsed time is
** less than or equal to the permitted minimum, re-allocate
@@ -96,19 +94,17 @@ else
** Don't need self-adjustment. Just allocate the
** arrays, and go.
*/
- abase=(double *)AllocateMemory(locfourierstruct->arraysize*sizeof(double),
- &systemerror);
- if(systemerror)
- { ReportError(errorcontext,systemerror);
- ErrorExit();
+ abase = malloc(locfourierstruct->arraysize * sizeof(double));
+ if (!abase) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ exit(1);
}
- bbase=(double *)AllocateMemory(locfourierstruct->arraysize*sizeof(double),
- &systemerror);
- if(systemerror)
- { ReportError(errorcontext,systemerror);
- FreeMemory((void *)abase,&systemerror);
- ErrorExit();
+ bbase = malloc(locfourierstruct->arraysize * sizeof(double));
+ if (!bbase) {
+ fprintf(stderr, "Error in %s, could not allocate memory. Exitting...\n", context);
+ free(abase);
+ exit(1);
}
}
/*
@@ -128,8 +124,8 @@ do {
** Clean up, calculate results, and go home.
** Also set adjustment flag to indicate no adjust code needed.
*/
-FreeMemory((void *)abase,&systemerror);
-FreeMemory((void *)bbase,&systemerror);
+free(abase);
+free(bbase);
locfourierstruct->fflops=iterations/(double)TicksToFracSecs(accumtime);