math.cls source

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

Get RexxLiterate at SourceForge.net. Fast, secure and Free Open Source software downloads
Generated on 22 Sep 2013 21:20:34 for OO_RexxMath by rexxliterate  0.0.1