📄 math.jc
字号:
/*
* math.jc
*
* This file demonstrates all the mathematical functions
* defined in the 'math' native type library.
*/
import stdlib;
import math;
/*
* function main()
*
* our main entry point function
*/
function string main( const array& args )
{
float f = 0.333;
if( args[1] == null )
stdlib::Printf( "No value specified, using %g\n", {f} );
else
f = stdlib::Atof( args[1] );
test( "abs", f, math::abs(f) );
test( "acos", f, math::acos(f) );
test( "asin", f, math::asin(f) );
test( "atan", f, math::atan(f) );
test( "atan2", f, 2, math::atan2(f, 2) );
test( "cos", f, math::cos(f) );
test( "cosh", f, math::cosh(f) );
test( "exp", f, math::exp(f) );
test( "fabs", f, math::fabs(f) );
test( "log", f, math::log(f) );
test( "log10", f, math::log10(f) );
test( "pow", f, 2, math::pow(f, 2) );
test( "sin", f, math::sin(f) );
test( "sinh", f, math::sinh(f) );
test( "tan", f, math::tan(f) );
test( "tanh", f, math::tanh(f) );
test( "sqrt", f, math::sqrt(f) );
test( "ceil", f, math::ceil(f) );
test( "floor", f, math::floor(f) );
test( "int", f, math::int(f) );
test( "frac", f, math::frac(f) );
test( "sgn", f, math::sgn(f) );
test( "min", f, 2, math::min(f, 2) );
test( "max", f, 2, math::max(f, 2) );
test( "fmin", f, 2, math::fmin(f, 2) );
test( "fmax", f, 2, math::fmax(f, 2) );
return "";
}
/*
* function test()
*
* prints function name, argument and result
*/
function test( const string& s, float f, float r )
{
stdlib::Printf( "%s(%g) = %g\n", {s, f, r} );
}
/*
* function test()
*
* prints function name, two arguments and result
*/
function test( const string& s, float f, float g, float r )
{
stdlib::Printf( "%s(%g, %g) = %g\n", {s, f, g, r} );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -