/******************************************************************************/ /* */ /* RVM.RxMath.cls - The rxmath library of the RVM */ /* ============================================== */ /* */ /* ooRexx's rxmath (extensions/rxmath/rxmath.cpp) is a library of native */ /* routines: RxCalcPi, RxCalcSqrt, RxCalcExp, RxCalcLog, RxCalcLog10, */ /* RxCalcSinH, RxCalcCosH, RxCalcTanH, RxCalcPower, RxCalcSin, RxCalcCos, */ /* RxCalcTan, RxCalcCotan, RxCalcArcSin, RxCalcArcCos, RxCalcArcTan, and */ /* MathLoadFuncs and MathDropFuncs, which do nothing but print the banner of */ /* MathLoadFuncs (below). It is one of the libraries of the RVM (RVMLibrary, */ /* in RVM.BIFs.cls, has its table). */ /* */ /* The arguments are checked here, as ooRexx's typed native routines check */ /* them, in order: a double (88.921), the precision, a positive whole number */ /* (88.905; by default NUMERIC DIGITS, at most 16), and the units of the */ /* trigonometric ones, whose first character must be D, R or G (88.916). The */ /* value is then the host's: the RVM of ooRexx calls the host's rxmath (the */ /* same C doubles, the same formatting), with the precision always given. */ /* */ /* This file is part of the RVM, the Rexx Virtual Machine */ /* [See https://rexx.epbcn.com/rexx-parser/] */ /* */ /* Copyright (c) 2026 Josep Maria Blasco */ /* */ /* License: Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0) */ /* */ /******************************************************************************/ -- Run routine 'r' (an entry of RxMathRoutines) with 'args' (checked for -- their number already: CheckRoutineArgs). ::Routine RxMathNative Public Use Strict Arg r, args, context key = r[4] Select Case key -- MathLoadFuncs([version]): with an argument, four lines (the last one -- empty) on the standard output (rxmath's fprintf to stdout, not -- .OUTPUT). When "LOAD" Then Do If args~hasIndex( 1 ) Then Do out = context~out out~lineOut( "rxmath 1.2 - REXX mathematical function library" ) out~lineOut( "Copyright (c) 2005-2021 Rexx Language Association." ) out~lineOut( "All rights reserved." ) out~lineOut( "" ) End Return "" End When "DROP" Then Return "" When "PI" Then Do p = Precision( args, 1, context ) Return RxCalcPi( p ) End When "POWER" Then Do x = DoubleArg( args, 1 ) y = DoubleArg( args, 2 ) p = Precision( args, 3, context ) Return RxCalcPower( x, y, p ) End When "SIN", "COS", "TAN", "COTAN", "ARCSIN", "ARCCOS", "ARCTAN" Then Do x = DoubleArg( args, 1 ) p = Precision( args, 2, context ) units = "D" If args~hasIndex( 3 ) Then Do units = str( args[3] ) If Pos( Upper( Left( units, 1 ) ), "DRG" ) == 0 | units == "" Then Raise Syntax 88.916 Array( 3, "D, R, or G", units ) End Select Case key When "SIN" Then Return RxCalcSin( x, p, units ) When "COS" Then Return RxCalcCos( x, p, units ) When "TAN" Then Return RxCalcTan( x, p, units ) When "COTAN" Then Return RxCalcCotan( x, p, units ) When "ARCSIN" Then Return RxCalcArcSin( x, p, units ) When "ARCCOS" Then Return RxCalcArcCos( x, p, units ) Otherwise Return RxCalcArcTan( x, p, units ) End End Otherwise Do x = DoubleArg( args, 1 ) p = Precision( args, 2, context ) Select Case key When "SQRT" Then Return RxCalcSqrt( x, p ) When "EXP" Then Return RxCalcExp( x, p ) When "LOG" Then Return RxCalcLog( x, p ) When "LOG10" Then Return RxCalcLog10( x, p ) When "SINH" Then Return RxCalcSinH( x, p ) When "COSH" Then Return RxCalcCosH( x, p ) When "TANH" Then Return RxCalcTanH( x, p ) Otherwise Nop End End End Raise Syntax 93.900 Additional( "RVM: rxmath routine" r[1] "is missing" ) -- Argument i, a double (ooRexx's doubleValue): a number, or nan, +infinity, -- -infinity (as written); else 88.921. Its string. ::Routine DoubleArg Use Strict Arg args, i v = args[i] s = str( v ) If isNum( s ) Then Return s If s == "nan" | s == "+infinity" | s == "-infinity" Then Return s If v~isA( .RVM.Obj ) Then s = ObjectText( v ) Raise Syntax 88.921 Array( i, s ) -- Argument i, the precision: a positive whole number (a native's argument: -- nativeWhole; else 88.905), or NUMERIC DIGITS when omitted. -- The host caps it at 16. ::Routine Precision Use Strict Arg args, i, context If \ args~hasIndex( i ) Then Return context~digits v = args[i] n = nativeWhole( v ) If n \== .Nil Then If n > 0 Then Return n If v~isA( .RVM.Obj ) Then s = ObjectText( v ) Else s = str( v ) Raise Syntax 88.905 Array( i, s ) ::Requires "modules/rvm/RVM.Number.cls" ::Requires "modules/rvm/RVM.Objects.cls"