00001 #!/usr/bin/rexx 00002 -- OO wrapper for the mathematical functions in the rxmath library package. 00003 -- Methods are renamed to their more commonly used names (e.g <i>RxCalcArcSin</i> 00004 -- becomes <i>asin</i>). 00005 00006 -- <b>math</b> is a subclass of <b>string</b>. 00007 ::class math public subclass string 00008 00009 -- The precision of the arguments and results 00010 -- Default is the NUMERIC DIGITS default 00011 -- Maximum is rxmath's maximum: 16 00012 -- @example num = .math~new(25,16) 00013 -- @example num~precision = 9 00014 -- 00015 ::attribute precision 00016 00017 -- Init is called from .math~new. 00018 -- Since .math is a subclass of .string a peculiar thing happens in that the 00019 -- first argument to ~new is not passed to ~init. That's why only the second 00020 -- argument ( the precision in digits of arguments and results ) is parsed. 00021 -- Following is an example of how to create a new .math instance: 00022 -- @example .math~new(114.2334,16) 00023 -- which results in a invocation of ~init as above: 00024 -- @param precision=(.context~digits) - where the default is taken from .context 00025 ::method init 00026 use strict arg precision=(.context~digits) 00027 self~init:super 00028 if (self+0)~datatype\='NUM' then do --if self is not a number 00029 raise syntax 93.904 array(1,self) -- self+0 by itself will 00030 end -- raise a syntax error 00031 if (precision~datatype('W') & precision>0) then do 00032 precision = precision~min(16) -- adjust maximum to rxmath's maximum 00033 self~precision = precision 00034 end 00035 else do 00036 self~precision = .context~digits 00037 end 00038 00039 -- Turns Degrees into Radians 00040 -- @return aNum - angle in Radians 00041 -- @example aRad = .math~new(30)~toRadians 00042 ::method toRadians 00043 numeric digits self~precision 00044 return self*self~pi/180 00045 00046 -- Turns Degrees into Radians 00047 -- @return aNum - angle in Radians 00048 -- @example radians = .math~new(30)~fromDegrees 00049 ::method fromDegrees 00050 numeric digits self~precision 00051 return self*self~pi/180 00052 00053 -- Turns Radians into Degrees 00054 -- @return aNum - angle in Degrees 00055 -- @example degrees = .math~new(3.5467)~toDegrees 00056 ::method toDegrees 00057 numeric digits self~precision 00058 return self*180/self~pi 00059 00060 -- Turns Radians into Degrees 00061 -- @return aNum - angle in Degrees 00062 -- @example degrees = .math~new(3.5467)~fromRadians 00063 ::method fromRadians 00064 numeric digits self~precision 00065 return self*180/self~pi 00066 00067 -- Yields the value of PI 00068 -- @return Pi 00069 -- @example PI = .math~pi 00070 ::method pi class 00071 return RxCalcPi(self~precision) 00072 00073 -- Gives the value of Pi 00074 -- @return Pi 00075 -- @example angle = .math~new(30); PI = angle~pi 00076 ::method pi 00077 return RxCalcPi(self~precision) 00078 00079 -- Calculates this objects square root 00080 -- @return aNum - being self's square root 00081 -- @example number = .math~new(16); root = number~sqrt 00082 ::method sqrt 00083 return RxCalcSqrt(self,self~precision) 00084 00085 -- Returns the exponential function (e**x) 00086 -- @return aNum - representing e**(self) 00087 -- @example x=.math~new(somenumber); etopowerx = x~exp 00088 ::method exp 00089 return RxCalcExp(self,self~precision) 00090 00091 -- Calculates a number raised to a specified power 00092 -- @param power - the power to which self will be raised 00093 -- @return aNum - self raised to the power specified as argument 00094 -- @example n = .math~new(aNumber); powered = n~power(6.5) 00095 ::method power 00096 use strict arg power 00097 return RxCalcPower(self,power,self~precision) 00098 00099 -- Retrieves a number's natural logarithm (inverse of exp) 00100 -- @return aNum - self's natural logarithm 00101 -- @example result = .math~new(aNumber)~log 00102 ::method log 00103 return RxCalcLog(self,self~precision) 00104 00105 -- Returns the base 10 logarithm 00106 -- @return aNum - self's base10 logarithm 00107 -- @example result = .math~new(4.6765434)~log10 00108 ::method log10 00109 return RxCalcLog10(self,self~precision) 00110 00111 -- Determines the sine, where self's angle is in degrees(D), radians(R) or grades(G) 00112 -- @param type='D' - type of self's angle unit (D, R or G), D is default 00113 -- @return aNum - the sine value 00114 -- @example aSin = .math~new(45)~sin('D') 00115 ::method sin 00116 use strict arg type='D' 00117 return RxCalcSin(self,self~precision,type) 00118 00119 -- Result is the cosine, where self's angle is in degrees(D), radians(R) or grades(G) 00120 -- @param type='D' - type of self's angle unit (D, R or G), D is default 00121 -- @return aNum - the cosine value 00122 -- @example aCos = .math~new(1)~cos('R') 00123 ::method cos 00124 use strict arg type='D' 00125 return RxCalcCos(self,self~precision,type) 00126 00127 -- Returns the tangent, where self's angle is in degrees(D), radians(R) or grades(G): 00128 -- @param type='D' - type of self's angle unit (D, R or G), D is default 00129 -- @return aNum - the tangent value 00130 -- @example aTan = .math~new(50)~tan('G') 00131 ::method tan 00132 use strict arg type='D' 00133 return RxCalcTan(self,self~precision,type) 00134 00135 -- Returns the cotangent, where self's angle is in degrees(D), radians(R) or grades(G): 00136 -- @param type='D' - type of self's angle unit (D, R or G), D is default 00137 -- @return aNum - the cotangent value 00138 -- @example aCotan = .math~new(50)~cotan 00139 ::method cotan 00140 use strict arg type='D' 00141 return RxCalcCotan(self,self~precision,type) 00142 00143 -- Finds the hyperbolic sine 00144 -- @return aNum - self's hyperbolic sine value 00145 -- @example aSinh = .math~new(aNumber)~sinh 00146 ::method sinh 00147 return RxCalcSinH(self,self~precision) 00148 00149 -- Returns the hyperbolic cosine 00150 -- @return aNum - self's hyperbolic cosine value 00151 -- @example aCosh = .math~new(aNumber)~cosh 00152 ::method cosh 00153 return RxCalcCosH(self,self~precision) 00154 00155 -- Calculates the hyperbolic tangent 00156 -- @return aNum - self's hyperbolic tangent 00157 -- @example aTanh = .math~new(aNumber)~tanh 00158 ::method tanh 00159 return RxCalcTanH(self,self~precision) 00160 00161 -- Yields the arcsine, where the result is in degrees(D), radians(R) or grades(G) 00162 -- @param type='D' - result's unit (D, R or G), D is default 00163 -- @return aNum - self's arcsine value in the unit specified by type 00164 -- @example aRad = .math~new(57.2)~asin('R') 00165 ::method asin 00166 use strict arg type='D' 00167 return RxCalcArcSin(self,self~precision,type) 00168 00169 -- Gives the arccosine, where the result is in degrees(D), radians(R) or grades(G) 00170 -- @param type='D' - result's unit (D, R or G), D is default 00171 -- @return aNum - self's arccosine value in the unit specified by type 00172 -- @example aDeg = .math~new(aNumber)~acos 00173 ::method acos 00174 use strict arg type='D' 00175 return RxCalcArcCos(self,self~precision,type) 00176 00177 -- Returns the arctangent, where the result is in degrees(D), radians(R) or grades(G) 00178 -- @param type='D' - result's unit (D, R or G), D is default 00179 -- @return aNum - self's arctangent value in the unit specified by type 00180 -- @example aGrade = .math~new(90)~atan('G') 00181 ::method atan 00182 use strict arg type='D' 00183 return RxCalcArcTan(self,self~precision,type) 00184 00185 ::requires 'rxmath' LIBRARY 00186
Generated on 22 Sep 2013 21:35:16 for OO_RexxMath by 0.0.1 |