source: git/factory/ftest/gcd.m4 @ 7bc116

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