source: git/factory/ftest/gcd.m4 @ ca53ce

fieker-DuValspielwiese
Last change on this file since ca53ce was ca53ce, checked in by Jens Schmidt <schmidt@…>, 27 years ago
Intermediate revision git-svn-id: file:///usr/local/Singular/svn/trunk@734 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.2 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id: gcd.m4,v 1.2 1997-09-24 07:27:46 schmidt Exp $ */
3
4ftestSetNameOfGame( gcd,
5        `"Usage: gcd [<options>] [<envSpec>] <f> <g> [<realResult>]\n"
6        "  calculates gcd( f, g ).\n"
7        "  If the gcd of f and g is already known, the optional argument\n"
8        "  <realResult> may be used to check the result of the gcd\n"
9        "  computation.\n"' )
10
11//{{{ docu
12//
13// ftestAlgorithm.m4 - ftestAlgorithm test program.
14//
15// To create ftestAlgorithm.cc, run m4 using the ftest_util.m4 library in
16// the following way:
17//
18// m4 ftest_util.m4 ftestAlgorithm.m4 > ftestAlgorithm.cc'
19//
20//}}}
21
22ftestPreprocInit();
23
24ftestGlobalInit();
25
26//
27// - functions.
28//
29
30//{{{ ftestStatusT gcdCheck ( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & result, const CanonicalForm & realResult )
31//{{{ docu
32//
33// gcdCheck() - check result of gcd().
34//
35//}}}
36ftestStatusT
37gcdCheck ( const CanonicalForm & f, const CanonicalForm & g, const CanonicalForm & result, const CanonicalForm & realResult )
38{
39    // if realResult is given, use it to compare with result
40    if ( ! realResult.isZero() )
41        if ( realResult == result )
42            return Passed;
43        else if ( -realResult == result )
44            return Passed;
45        else
46            return Failed;
47
48    if ( result.isZero() )
49        if ( f.isZero() && g.isZero() )
50            return Passed;
51        else
52            return Failed;
53
54    if ( divides( result, f ) && divides( result, g ) )
55        if ( gcd( f/result, g/result ).isOne() )
56            return Passed;
57        else
58            return Failed;
59    else
60        return Failed;
61}
62//}}}
63
64//
65// - main program.
66//
67int
68main ( int argc, char ** argv )
69{
70    // initialization
71    ftestMainInit();
72
73    // declare input and output variables
74    ftestOutVar( CanonicalForm, result );
75    ftestInVar( CanonicalForm, f );
76    ftestInVar( CanonicalForm, g );
77    ftestInVar( CanonicalForm, realResult );
78
79    // process argument list and set environment
80    ftestGetOpts();
81    ftestGetEnv();
82    ftestGetInVar( f );
83    ftestGetInVar( g );
84    ftestGetInVar( realResult, 0 );
85
86    // do the test!
87    ftestRun(
88        result = gcd( f, g ); );
89
90    // do the check
91    ftestCheck( gcdCheck( f, g, result, realResult ) );
92
93    // print results
94    ftestOutput( "gcd(f, g) =", result );
95
96    // clean up
97    ftestMainExit();
98}
Note: See TracBrowser for help on using the repository browser.