eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Math':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: Math


Inheritance:

   Object
   |
   +--Math

Package:
stx:libjavascript
Category:
Languages-JavaScript-Framework
Version:
rev: 1.9 date: 2022/01/07 22:16:02
user: cg
file: Math.st directory: libjavascript
module: stx stc-classLibrary: libjavascript

Description:


Simulates the javascript Math protocol

allows for
    Math.sin(foo)
or
    Math.atan2(a,b)

copyright

COPYRIGHT (c) 2008 by eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

constants
o  E
Eulers constant, the base of the natural logarithm; approx 2.718

Usage example(s):

     JavaScriptParser 
        evaluate:'Math.E;'    

o  LN10
natural logarithm of 10, approx 2.302

Usage example(s):

     JavaScriptParser 
        evaluate:'Math.LN10;'    

o  LN2
natural logarithm of 2, approx 0.693

Usage example(s):

     JavaScriptParser 
        evaluate:'Math.LN2;'    

o  LOG10E
base 10 logarithm of E; approx. 0.434

Usage example(s):

     JavaScriptParser 
        evaluate:'Math.LOG10E;'    

o  LOG2E
base2 logarithm of E; approx. 1.442

Usage example(s):

     JavaScriptParser 
        evaluate:'Math.LOG2E;'    

o  NEGATIVE_INFINITY
-inf

Usage example(s):

     JavaScriptParser evaluate:'Math.NEGATIVE_INFINITY;'    

o  NaN
not a number

Usage example(s):

     JavaScriptParser evaluate:'Math.NaN;'    

o  PI
pi; approx 3.14159

Usage example(s):

     JavaScriptParser 
        evaluate:'Math.PI;'    

o  POSITIVE_INFINITY
+Inf

Usage example(s):

     JavaScriptParser evaluate:'Math.POSITIVE_INFINITY;'    

o  SQRT1_2
square root of 1/2; approx 0.707

Usage example(s):

     JavaScriptParser 
        evaluate:'Math.SQRT1_2;'    

o  SQRT2
square root of 2; approx. 1.414

Usage example(s):

     JavaScriptParser 
        evaluate:'Math.SQRT2;'    

min & max
o  max
returns the largest of 0 to 6 args

Usage example(s):

     JavaScriptParser 
        evaluate:'Math.max();'    

     JavaScriptParser 
        evaluate:'Math.max(1);'    

     JavaScriptParser 
        evaluate:'Math.max(10,2);'    

     JavaScriptParser 
        evaluate:'Math.max(10,5,20);'    

o  max: n1
returns the largest of 0 to 6 args

o  max: n1 _: n2
returns the largest of 0 to 6 args

o  max: n1 _: n2 _: n3
returns the largest of 0 to 6 args

o  max: n1 _: n2 _: n3 _: n4
returns the largest of 0 to 6 args

o  max: n1 _: n2 _: n3 _: n4 _: n5
returns the largest of 0 to 6 args

o  max: n1 _: n2 _: n3 _: n4 _: n5 _: n6
returns the largest of 0 to 6 args

o  min
returns the smallest of 0 to 6 args

Usage example(s):

     JavaScriptParser 
        evaluate:'Math.min();'    
     JavaScriptParser 
        evaluate:'Math.min(1);'    
     JavaScriptParser 
        evaluate:'Math.min(10,2);'    
     JavaScriptParser 
        evaluate:'Math.min(10,5,20);'    

o  min: n1
returns the smallest of 0 to 6 args

o  min: n1 _: n2
returns the smallest of 0 to 6 args

o  min: n1 _: n2 _: n3
returns the smallest of 0 to 6 args

o  min: n1 _: n2 _: n3 _: n4
returns the smallest of 0 to 6 args

o  min: n1 _: n2 _: n3 _: n4 _: n5
returns the smallest of 0 to 6 args

o  min: n1 _: n2 _: n3 _: n4 _: n5 _: n6
returns the smallest of 0 to 6 args

misc math
o  abs: aNumber
returns the absolute value of a number

o  binco: n _: k
returns the binomialcoefficient C(n,k) (n over k, choose k from n)

o  cbrt: aNumber
returns the cubic root of aNumber

o  ceil: aNumber
returns the smallest integer greater than or equal to aNumber

o  exp: aNumber
returns E^aNumber

o  fac: aNumber
returns the factorial of aNumber

o  floor: aNumber
returns the largest integer less than or equal to aNumber

o  gcd: a _: b
returns the greatest common divisor of a and b

o  ln: aNumber
returns the natural logarithm of aNumber.

o  log10: aNumber
returns the log base 10 of aNumber.
In contrast to JavaScript (and to be compatible to Smalltalk),
this raises an error for zero or negative arguments

o  log2: aNumber
returns the log base 2 of aNumber.
In contrast to JavaScript (and to be compatible to Smalltalk),
this raises an error for zero or negative arguments

o  log: aNumber
returns the log base E of aNumber.
ATTENTION:
JS log is a base E log
ST log is a base 10 log (use ln for base E)
in JS, better use log10 to make things explicit.

o  pow: base _: exp
returns base^exp

o  random
returns a pseudo random number between 0 and 1

Usage example(s):

     JavaScriptParser 
        evaluate:'Math.random();'              

o  random: min _: max
returns a pseudo random number between min and max

o  randomInteger: min _: max
returns a pseudo random number between min and max

o  round: aNumber
returns the value of aNumber rounded to the nearest integer

o  sign: aNumber
returns the sign of aNumber

o  sqrt: aNumber
returns the square root of aNumber

o  trunc: aNumber
returns the value of aNumber truncated to the nearest integer towards zero

queries
o  isUtilityClass

trigonometric
o  acos: aNumber
returns the arccosine (in radians) of a number

o  acosh: aNumber
returns the hyperbolic arcosine (in radians) of a number

o  asin: aNumber
returns the arcsine (in radians) of a number

o  asinh: aNumber
returns the hyperbolic arsine (in radians) of a number

o  atan2: x _: y
returns the arctangent of the quotient of its arguments (in radians)

o  atan: aNumber
returns the arctangent (in radians) of a number

o  atanh: aNumber
returns the hyperbolic artangent (in radians) of a number

o  cos: aNumber
returns the cosine of a number (given in radians)

o  cosh: aNumber
returns the hyperbolic cosine of a number (given in radians)

o  degreesToRadians: aNumber
converts degrees to radians

o  radiansToDegrees: aNumber
converts radians to degrees

o  sin: aNumber
returns the sine of a number (given in radians)

o  sinh: aNumber
returns the hyperbolic sine of a number (given in radians)

o  tan: aNumber
returns the tangent of a number (given in radians)

o  tanh: aNumber
returns the hyperbolic tangent of a number (given in radians)



ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sat, 21 Dec 2024 15:59:57 GMT