/[ascend]/trunk/base/generic/compiler/fractions.h
ViewVC logotype

Diff of /trunk/base/generic/compiler/fractions.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 53 by ben.allan, Sun Dec 26 20:06:01 2004 UTC revision 54 by jds, Tue Aug 2 11:20:09 2005 UTC
# Line 1  Line 1 
1  /**<  /*
2   *  Fraction module for ASCEND   *  Fraction module for ASCEND
3   *  by Tom Epperly   *  by Tom Epperly
4   *  8/18/89   *  8/18/89
# Line 27  Line 27 
27   *  COPYING.   *  COPYING.
28   */   */
29    
30  #ifndef __FRACTIONS_H_SEEN__  /** @file
31  #define __FRACTIONS_H_SEEN__   *  Fraction module for ASCEND.
32     *  <pre>
   
 /**<  
33   *  When #including fractions.h, make sure these files are #included first:   *  When #including fractions.h, make sure these files are #included first:
34   *         NO INCLUDES NEEDED   *         #include "utilities/ascConfig,h"
35     *  </pre>
36   */   */
37    
38    #ifndef __FRACTIONS_H_SEEN__
39    #define __FRACTIONS_H_SEEN__
40    
41    /** The type of a fraction numerator or denominator. */
42  #define FRACPART short  #define FRACPART short
43    /** The maximum FRACPART value. */
44  #define FRACMAX SHRT_MAX  #define FRACMAX SHRT_MAX
45    
46    /** Fraction data structure. */
47  struct fraction {  struct fraction {
48    FRACPART numerator,denominator;    FRACPART numerator;
49      FRACPART denominator;
50  };  };
51    
52  extern struct fraction CreateFraction(short,short);  extern struct fraction CreateFraction(short n, short d);
53  /**<  /**<
54   *  struct fraction CreateFraction(n,d)   *  <!--  struct fraction CreateFraction(n,d)                          -->
55   *  short n,d;   *  <!--  short n,d;                                                   -->
56   *  n - numerator   *  Create a fraction (n/d).
57   *  d - denominator   *  Specify the numerator (n) and denominator (d).
58   */   */
59    
60  extern struct fraction Simplify(struct fraction);  extern struct fraction Simplify(struct fraction f);
61  /**<  /**<
62   *  struct fraction Simplify(f)   *  <!--  struct fraction Simplify(f)                                  -->
63   *  struct fraction f;   *  <!--  struct fraction f;                                           -->
64   *  Simplify the fraction.  This forces the denominator to be >= 0; so   *  Simplify the fraction.  This forces the denominator to be >= 0; so
65   *  if the fraction is negative, the numerator will be negative.   *  if the fraction is negative, the numerator will be negative.
66   */   */
67    
68  #define Numerator(f) ((f).numerator)  #define Numerator(f) ((f).numerator)
69  /**<  /**<
70   *  macro Numerator(f)   *  <!--  macro Numerator(f)                                           -->
71   *  struct fraction f;   *  <!--  struct fraction f;                                           -->
72   *  return the numerator of f   *  Return the numerator of f as a FRACPART.
73   */   */
74    
75  #define Denominator(f) ((f).denominator)  #define Denominator(f) ((f).denominator)
76  /**<  /**<
77   *  macro Denominator(f)   *  <!--  macro Denominator(f)                                         -->
78   *  struct fraction f;   *  <!--  struct fraction f;                                           -->
79   *  return the denominator of f.   *  Return the denominator of f as a FRACPART.
80   */   */
81    
82  extern struct fraction AddF(struct fraction,struct fraction);  extern struct fraction AddF(struct fraction f1, struct fraction f2);
83  /**<  /**<
84   *  struct fraction AddF(f1,f2)   *  <!--  struct fraction AddF(f1,f2)                                  -->
85   *  struct fraction f1,f2;   *  <!--  struct fraction f1,f2;                                       -->
86   *  Return f1+f2 simplified.   *  Return f1+f2 simplified.
87   */   */
88    
89  extern struct fraction SubF(struct fraction,struct fraction);  extern struct fraction SubF(struct fraction f1, struct fraction f2);
90  /**<  /**<
91   *  struct fraction SubF(f1,f2)   *  <!--  struct fraction SubF(f1,f2)                                  -->
92   *  struct fraction f1,f2;   *  <!--  struct fraction f1,f2;                                       -->
93   *  Return f1-f2 simplified.   *  Return f1-f2 simplified.
94   */   */
95    
96  extern struct fraction MultF(struct fraction,struct fraction);  extern struct fraction MultF(struct fraction f1, struct fraction f2);
97  /**<  /**<
98   *  struct fraction MultF(f1,f2)   *  <!--  struct fraction MultF(f1,f2)                                 -->
99   *  struct fraction f1,f2;   *  <!--  struct fraction f1,f2;                                       -->
100   *  Return f1*f2 simplified.   *  Return f1*f2 simplified.
101   */   */
102    
103  extern struct fraction DivF(struct fraction,struct fraction);  extern struct fraction DivF(struct fraction f1, struct fraction f2);
104  /**<  /**<
105   *  struct fraction DivF(f1,f2)   *  <!--  struct fraction DivF(f1,f2)                                  -->
106   *  struct fraction f1,f2;   *  <!--  struct fraction f1,f2;                                       -->
107   *  Return f1/f2 simplified.   *  Return f1/f2 simplified.
108   */   */
109    
110  extern int CmpF(struct fraction,struct fraction);  extern int CmpF(struct fraction f1, struct fraction f2);
111  /**<  /**<
112   *  int CmpF(f1,f2)   *  <!--  int CmpF(f1,f2)                                              -->
113   *  struct fraction f1,f2;   *  <!--  struct fraction f1,f2;                                       -->
114   *  Return -1,0,1 if f1 is <,=, or > than f2 respectively.   *  Return -1,0,1 if f1 is <,=, or > than f2 respectively.
115   */   */
116    
117  extern struct fraction NegateF(struct fraction);  extern struct fraction NegateF(struct fraction f);
118  /**<  /**<
119   *  struct fraction NegateF(f)   *  <!--  struct fraction NegateF(f)                                   -->
120   *  struct fraction f;   *  <!--  struct fraction f;                                           -->
121   *  Returned fraction equal -f.   *  Returned fraction equal -f.
122   */   */
123  #endif /**< __FRACTIONS_H_SEEN__ */  
124    #endif /* __FRACTIONS_H_SEEN__ */
125    

Legend:
Removed from v.53  
changed lines
  Added in v.54

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22