1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// test_modulo -- quick-n-dirty test of modulo_reduce()
// $Header$
#include <stdio.h>
#include <assert.h>
#include "stdc.h"
#include "util.hh"
using namespace AHFinderDirect;
using jtutil::error_exit;
using jtutil::fuzzy;
// prototypes
void tryit(double x, double xmod, double xmin, double xmax, double correct);
//******************************************************************************
int main()
{
// x xmod xmin xmax correct
tryit( 0.5, 1.0, 0.0, 1.0, 0.5);
tryit( 0.0, 1.0, 0.0, 1.0, 0.0);
tryit( 1.0, 1.0, 0.0, 1.0, 1.0);
tryit( 2.0, 1.0, 0.0, 1.0, 1.0);
tryit( 1.5, 1.0, 0.0, 1.0, 0.5);
tryit( -0.6, 1.0, 0.0, 1.0, 0.4);
tryit( -3.6, 1.0, 0.0, 1.0, 0.4);
tryit(-145.0, 360.0, 180.0, 270.0, 215.0);
printf("all ok!\n");
}
//******************************************************************************
void tryit(double x, double xmod, double xmin, double xmax, double correct)
{
printf("trying %g mod %g [%g,%g] ==> ",
x, xmod, xmin, xmax);
double got = jtutil::modulo_reduce(x, xmod, xmin, xmax);
if (fuzzy<double>::EQ(got, correct))
then printf("ok\n");
else {
error_exit(ERROR_EXIT,
"no: got %g, correct %g\n", got, correct); /*NOTREACHED*/
}
}
|