Real constants and functions: Difference between revisions

From Rosetta Code
Content added Content deleted
(Added PicoLisp)
Line 517: Line 517:
=={{header|OCaml}}==
=={{header|OCaml}}==
Unless otherwise noted, the following functions are for floats only:
Unless otherwise noted, the following functions are for floats only:
<lang ocaml>sqrt x;; (* square root *)
<lang ocaml>sqrt x (* square root *)
log x;; (* natural logarithm--log base 10 also available (log10) *)
log x (* natural logarithm--log base 10 also available (log10) *)
exp x;; (* exponential *)
exp x (* exponential *)
abs_float x;; (* absolute value *)
abs_float x (* absolute value *)
abs x;; (* absolute value (for integers) *)
abs x (* absolute value (for integers) *)
floor x;; (* floor *)
floor x (* floor *)
ceil x;; (* ceiling *)
ceil x (* ceiling *)
x ** y; (* power *)</lang>
x ** y (* power *)</lang>


=={{header|Octave}}==
=={{header|Octave}}==

Revision as of 11:52, 27 June 2010

Task
Real constants and functions
You are encouraged to solve this task according to the task description, using any language you may know.

Show how to use the following math constants and functions in your language (if not available, note it):

  • (Euler's number)
  • square root
  • logarithm (any base allowed)
  • exponential ()
  • absolute value (a.k.a. "magnitude")
  • floor (largest integer less than or equal to this number--not the same as truncate or int)
  • ceiling (smallest integer not less than this number--not the same as round up)
  • power ()

See also Trigonometric Functions

ActionScript

Actionscript has all the functions and constants mentioned in the task, available in the Math class. <lang ActionScript>Math.E; //e Math.PI; //pi Math.sqrt(u); //square root of u Math.log(u); //natural logarithm of u Math.exp(u); //e to the power of u Math.abs(u); //absolute value of u Math.floor(u);//floor of u Math.ceil(u); //ceiling of u Math.pow(u,v);//u to the power of v</lang> The Math class also contains several other constants. <lang ActionScript>Math.LN10; // natural logarithm of 10 Math.LN2; // natural logarithm of 2 Math.LOG10E; // base-10 logarithm of e Math.LOG2E; // base-2 logarithm of e Math.SQRT1_2;// square root of 1/2 Math.SQRT2; //square root of 2</lang>

Ada

Most of the constants and functions used in this task are defined in the pre-defined Ada package Ada.Numerics.Elementary_Functions. <lang ada>Ada.Numerics.e -- Euler's number Ada.Numerics.pi -- pi sqrt(x) -- square root log(x, base) -- logarithm to any specified base exp(x) -- exponential abs(x) -- absolute value S'floor(x) -- Produces the floor of an instance of subtype S S'ceiling(x) -- Produces the ceiling of an instance of subtype S x**y -- x raised to the y power</lang>

ALGOL 68

<lang algol68>REAL x:=exp(1), y:=4*atan(1); printf(($g(-8,5)"; "$,

   exp(1),    # e #
   pi,        # pi #
   sqrt(x),   # square root #
   log(x),    # logarithm base 10 #
   ln(x),     # natural logarithm #
   exp(x),    # exponential #
   ABS x,     # absolute value #
   ENTIER x,  # floor #
  -ENTIER -x, # ceiling #
   x ** y     # power #

))</lang> Output:

 2.71828;  3.14159;  1.64872;  0.43429;  1.00000; 15.15426;  2.71828;  2.00000;  3.00000; 23.14069; 

ALGOL 68 also includes assorted long, short and complex versions of the above, eg: long exp, long long exp, short exp, complex exp etc.

And assorted trig functions: sin(x), arcsin(x), cos(x), arccos(x), tan(x), arctan(x), arctan2(x,y), sinh(x), arcsinh(x), cosh(x), arccosh(x), tanh(x) AND arctanh(x).

AutoHotkey

The following math functions are built into AutoHotkey: <lang autohotkey>Sqrt(Number) ; square root Log(Number) ; returns logarithm (base 10) Ln(Number) ; returns natural logarithm (base e) Exp(N) ; returns e to the N power Abs(Number) ; absolute value Floor(Number) ; floor value Ceil(Number) ; ceiling value</lang> The following math operations are not built-in functions but can be performed using Autohotkey: <lang autohotkey>x**y ; x to the y power pi() { ; will return pi when custom function is called return 22/7 }</lang> The following are additional trigonometric functions that are built into the Autohotkey language: <lang autohotkey>Sin(Number) ; sine Cos(Number) ; cosine Tan(Number) ; tangent ASin(Number) ; arcsine ACos(Number) ; arccosine ATan(Number) ; arctangent</lang>

AWK

The following scriptlets demonstrate some of the required items. abs() was trivially implemented. Missing are:

  • floor(), ceil() -- could be easily implemented as well

The pow() example is from Exponentiation operator. <lang awk>$ awk 'func abs(x){return(x<0?-x:x)}BEGIN{print exp(1),atan2(1,1)*4,sqrt(2),log(2),abs(-42)}' 2.71828 3.14159 1.41421 0.693147 42

$ awk 'func pow(x,n){r=1;for(i=0;i<n;i++)r=r*x;return r}{print pow($1,$2)}' 2.5 2 6.25</lang>

BASIC

Works with: QuickBasic version 4.5

<lang qbasic>abs(x) 'absolute value sqr(x) 'square root exp(x) 'exponential log(x) 'natural logarithm x ^ y 'power 'floor, ceiling, e, and pi not available</lang>

C

Most of the following functions take a double. <lang c>#include <math.h>

M_E; /* e - not standard but offered by most implementations */ M_PI; /* pi - not standard but offered by most implementations */ sqrt(x); /* square root--cube root also available in C99 (cbrt) */ log(x); /* natural logarithm--log base 10 also available (log10) */ exp(x); /* exponential */ abs(x); /* absolute value (for integers) */ fabs(x); /* absolute value (for doubles) */ floor(x); /* floor */ ceil(x); /* ceiling */ pow(x,y); /* power */</lang>

To access the M_PI, etc. constants in Visual Studio, you may need to add the line #define _USE_MATH_DEFINES before the #include <math.h>.

C++

<lang cpp>#include <iostream>

  1. include <cmath>
  1. ifdef M_E

static double euler_e = M_E;

  1. else

static double euler_e = std::exp(1); // standard fallback

  1. endif
  1. ifdef M_PI

static double pi = M_PI;

  1. else

static double pi = std::acos(-1);

  1. endif

int main() {

 std::cout << "e = " << euler_e
           << "\npi = " << pi
           << "\nsqrt(2) = " << std::sqrt(2.0)
           << "\nln(e) = " << std::log(e)
           << "\nlg(100) = " << std::log10(100.0)
           << "\nexp(3) = " << std::exp(3.0)
           << "\n|-4.5| = " << std::abs(-4.5)   // or std::fabs(4.0); both work in C++
           << "\nfloor(4.5) = " << std::floor(4.5)
           << "\nceiling(4.5) = " << std::ceil(4.5)
           << "\npi^2 = " << std::pow(pi,2.0) << std::endl;

}</lang>

C#

<lang csharp>using System;

class Program {

   static void Main(string[] args) {        
       Console.WriteLine(Math.E); //E
       Console.WriteLine(Math.PI); //PI
       Console.WriteLine(Math.Sqrt(10)); //Square Root
       Console.WriteLine(Math.Log(10)); // Logarithm
       Console.WriteLine(Math.Log10(10)); // Base 10 Logarithm
       Console.WriteLine(Math.Exp(10)); // Exponential
       Console.WriteLine(Math.Abs(10)); //Absolute value
       Console.WriteLine(Math.Floor(10.0)); //Floor
       Console.WriteLine(Math.Ceiling(10.0)); //Ceiling
       Console.WriteLine(Math.Pow(2, 5)); // Exponentiation
   }

}</lang>

Chef

See Basic integer arithmetic#Chef for powers.

Clojure

Translation of: Java

which is directly available.

<lang lisp>(Math/E); //e (Math/PI); //pi (Math/sqrt x); //square root--cube root also available (cbrt) (Math/log x); //natural logarithm--log base 10 also available (log10) (Math/exp x); //exponential (Math/abs x); //absolute value (Math/floor x); //floor (Math/ceil x); //ceiling (Math/pow x y); //power</lang>

Clojure does provide arbitrary precision versions as well:

<lang lisp>(ns user (:require [clojure.contrib.math :as math])) (math/sqrt x) (math/abs x) (math/floor x) (math/ceil x) (math/expt x y) </lang>

.. and as multimethods that can be defined for any type (e.g. complex numbers).

<lang lisp>(ns user (:require [clojure.contrib.generic.math-functions :as generic])) (generic/sqrt x) (generic/log x) (generic/exp x) (generic/abs x) (generic/floor x) (generic/ceil x) (generic/pow x y)</lang>

Common Lisp

<lang lisp>pi ;pi constant (sqrt x) ;square root (log x) ;natural logarithm (log x 10) ;logarithm base 10 (exp x) ;exponential (abs x) ;absolute value (floor x) ;floor (ceiling x) ;ceiling (expt x y) ;power</lang>

D

<lang d>import std.math ; // need to import this module E // Euler's number PI // pi constant sqrt(x) // square root log(x) // natural logarithm log10(x) // logarithm base 10 log2(x) // logarithm base 2 exp(x) // exponential abs(x) // absolute value (= magnitude for complex) floor(x) // floor ceil(x) // ceiling pow(x,y) // power</lang>

E

<lang e>? 1.0.exp()

  1. value: 2.7182818284590455

? 0.0.acos() * 2

  1. value: 3.141592653589793

? 2.0.sqrt()

  1. value: 1.4142135623730951

? 2.0.log()

  1. value: 0.6931471805599453

? 5.0.exp()

  1. value: 148.4131591025766

? (-5).abs()

  1. value: 5

? 1.2.floor()

  1. value: 1

? 1.2.ceil()

  1. value: 2

? 10 ** 6

  1. value: 1000000</lang>

Factor

<lang factor> e  ! e pi  ! π sqrt  ! square root log  ! natural logarithm exp  ! exponentiation abs  ! absolute value floor  ! greatest whole number smaller than or equal ceiling  ! smallest whole number greater than or equal truncate  ! remove the fractional part (i.e. round towards 0) round  ! round to next whole number ^  ! power</lang>

Forth

<lang forth>1e fexp fconstant e 0e facos 2e f* fconstant pi \ predefined in gforth fsqrt ( f -- f ) fln ( f -- f ) \ flog for base 10 fexp ( f -- f ) fabs ( f -- f ) floor ( f -- f ) \ round towards -inf

ceil ( f -- f ) fnegate floor fnegate ; \ not standard, though fround is available

f** ( f e -- f^e )</lang>

Fortran

<lang fortran>e  ! Not available. Can be calculated EXP(1) pi  ! Not available. Can be calculated 4.0*ATAN(1.0) SQRT(x)  ! square root LOG(x)  ! natural logarithm LOG10(x)  ! logarithm to base 10 EXP(x)  ! exponential ABS(x)  ! absolute value FLOOR(x)  ! floor - Fortran 90 or later only CEILING(x) ! ceiling - Fortran 90 or later only x**y  ! x raised to the y power</lang>

Go

<lang go>import "math"

math.E // e - not standard but offered by most implementations math.Pi // pi - not standard but offered by most implementations math.Sqrt(x) // square root--cube root also available (math.Cbrt) math.Log(x) // natural logarithm--log base 10, 2 also available (math.Log10, math.Log2) math.Exp(x) // exponential--exp base 10 also available (math.Pow10) math.Fabs(x) // absolute value math.Floor(x) // floor math.Ceil(x) // ceiling math.Pow(x,y) // power</lang>

To access the M_PI, etc. constants in Visual Studio, you may need to add the line #define _USE_MATH_DEFINES before the #include <math.h>.

Groovy

Math constants and functions are as outlined in the Java example, except as follows:

Absolute Value

In addition to the java.lang.Math.abs() method, each numeric type has an abs() method, which can be invoked directly on the number: <lang groovy>println ((-22).abs())</lang> Output:

22

Power

In addition to the java.lang.Math.pow() method, each numeric type works with the power operator (**), which can be invoked as an in-fix operator between two numbers: <lang groovy>println 22**3.5</lang> Output:

49943.547010599876

Power results are not defined for all possible pairs of operands. Any power operation that does not have a result returns a 64-bit IEEE NaN (Not a Number) value. <lang groovy>println ((-22)**3.5)</lang> Output:

NaN

Also note that at the moment (--21:58, 24 May 2009 (UTC)) Groovy (1.6.2) gives a mathematically incorrect result for "0**0". The correct result should be "NaN", but the Groovy operation result is "1".

Haskell

The operations are defined for the various numeric typeclasses, as defined in their type signature. <lang haskell>exp 1 -- Euler number pi -- pi sqrt x -- square root log x -- natural logarithm exp x -- exponential abs x -- absolute value floor x -- floor ceiling x -- ceiling x ** y -- power (e.g. floating-point exponentiation) x ^ y -- power (e.g. integer exponentiation, nonnegative y only) x ^^ y -- power (e.g. integer exponentiation of rationals, also negative y)</lang>

HicEst

Except for x^y, this is identical to Fortran: <lang HicEst>e  ! Not available. Can be calculated EXP(1) pi  ! Not available. Can be calculated 4.0*ATAN(1.0) x^0.5  ! square root LOG(x)  ! natural logarithm LOG(x, 10) ! logarithm to base 10 EXP(x)  ! exponential ABS(x)  ! absolute value FLOOR(x)  ! floor CEILING(x) ! ceiling x**y  ! x raised to the y power x^y  ! same as x**y</lang>

Icon and Unicon

Icon

<lang Icon>link numbers # for floor and ceil

procedure main() write("e=",&e) write("pi=",&pi) write("phi=",&phi) write("sqrt(2)=",sqrt(2.0)) write("log(e)=",log(&e)) write("log(100.,10)=",log(100,10)) write("exp(1)=",exp(1.0)) write("abs(-2)=",abs(-2)) write("floor(-2.2)=",floor(-2.2)) write("ceil(-2.2)=",ceil(-2.2)) write("power: 3^3=",3^3) end</lang>

numbers provides floor and ceiling

Sample output:

e=2.718281828459045
pi=3.141592653589793
phi=1.618033988749895
sqrt(2)=1.414213562373095
log(e)=1.0
log(100.,10)=2.0
exp(1)=2.718281828459045
abs(-2)=2
floor(-2.2)=-2
ceil(-2.2)=-3

Unicon

This Icon solution works in Unicon.

J

The examples below require arguments (x and y) to be numeric nouns. <lang j>e =. 1x1 NB. Euler's number, specified as a numeric literal. e =. ^ 1 NB. Euler's number, computed by exponentiation. pi=. 1p1 NB. pi, specified as a numeric literal. pi=. o.1 NB. pi, computed trigonometrically. magnitude_of_x =. |x floor_of_x =. <.x ceiling_of_x =. >.x natural_log_of_x =. ^.x base_x_log_of_y =. x^.y x_squared =. *:x NB. special form x_squared =. x^2 NB. exponential form square_root_of_x =. %:x NB. special form square_root_of_x =. x^0.5 NB. exponential form x_to_the_y_power =. x^y</lang>

Java

All of these functions are in Java's Math class which, does not require any imports: <lang java>Math.E; //e Math.PI; //pi Math.sqrt(x); //square root--cube root also available (cbrt) Math.log(x); //natural logarithm--log base 10 also available (log10) Math.exp(x); //exponential Math.abs(x); //absolute value Math.floor(x); //floor Math.ceil(x); //ceiling Math.pow(x,y); //power</lang>

JavaScript

<lang javascript>Math.E Math.PI Math.sqrt(x) Math.log(x) Math.exp(x) Math.abs(x) Math.floor(x) Math.ceil(x) Math.pow(x,y)</lang>

Works with: UCB Logo

<lang logo>make "e exp 1 make "pi 2*(RADARCTAN 0 1) sqrt :x ln :x exp :x

there is no standard abs, floor, or ceiling; only INT and ROUND.

power :x :y</lang>

Mathematica

<lang Mathematica>E Pi Sqrt[x] Log[x] Log[b,x] Exp[x] Abs[x] Floor[x] Ceiling[x] Power[x, y]</lang> Where x is the number, and b the base. Exp[x] can also be inputted as E^x or Ex and Power[x,y] can be also inputted as x^y or xy. All functions work with symbols, integers, floats and can be complex. Abs giving the modulus (|x|) if the argument is a complex number. Constant like E and Pi are kep unevaluated until someone explicitly tells it to give a numerical approximation: N[Pi,n] gives Pi to n-digit precision. Functions given an exact argument will be kept unevaluated if the answer can't be written more compact, approximate arguments will always be evaluated: <lang Mathematica>Log[1.23] => 0.207014 Log[10] => Log[10] Log[10,100] => 2 Log[E^4] => 4 Log[1 + I] => Log[1+I] Log[1. + I] => 0.346574 + 0.785398 I Ceiling[Pi] => 4 Floor[Pi] => 3 Sqrt[2] => Sqrt[2] Sqrt[4] => 2 Sqrt[9/2] => 3/Sqrt[2] Sqrt[3.5] => 1.87083 Sqrt[-5 + 12 I] => 2 + 3 I Sqrt[-4] => 2I Exp[2] => E^2 Exp[Log[4]] => 4</lang>

MAXScript

<lang maxscript>e -- Euler's number pi -- pi log x -- natural logarithm log10 x -- log base 10 exp x -- exponantial abs x -- absolute value floor x -- floor ceil x -- ceiling pow x y -- power</lang>

Metafont

<lang metafont>show mexp(256);  % outputs e; since MF uses mexp(x) = exp(x/256) show 3.14159;  % no pi constant built in; of course we can define it

                 % in several ways... even computing
                 % C/2r (which would be funny since MF handles paths,
                 % and a circle is a path...)

show sqrt2;  % 1.41422, or in general sqrt(a) show mexp(256*x); % see e. show abs(x);  % returns |x| (the absolute value of the number x, or

                 % the length of the vector x); it is the same as
                 % length(x); plain Metafont in fact says:
                 % let abs = length;

show floor(x);  % floor show ceiling(x);  % ceiling show x**y;  % ** is not a built in: it is defined in the basic macros

                 % set for Metafont (plain Metafont) as a primarydef</lang>

Modula-3

Modula-3 uses a module that is a wrapper around C's math.h.

Note that all of these procedures (except the built ins) take LONGREALs as their argument, and return LONGREALs. <lang modula3>Math.E; Math.Pi; Math.sqrt(x); Math.log(x); Math.exp(x); ABS(x); (* Built in function. *) FLOOR(x); (* Built in function. *) CEILING(x); (* Built in function. *) Math.pow(x, y);</lang>

OCaml

Unless otherwise noted, the following functions are for floats only: <lang ocaml>sqrt x (* square root *) log x (* natural logarithm--log base 10 also available (log10) *) exp x (* exponential *) abs_float x (* absolute value *) abs x (* absolute value (for integers) *) floor x (* floor *) ceil x (* ceiling *) x ** y (* power *)</lang>

Octave

<lang octave>e  % e pi  % pi sqrt(pi)  % square root log(e)  % natural logarithm exp(pi)  % exponential abs(-e)  % absolute value floor(pi) % floor ceil(pi)  % ceiling e**pi  % power</lang>

Oz

<lang oz>{ForAll

[
 {Exp 1.}           %% 2.7183   Euler's number: not predefined
 4. * {Atan2 1. 1.} %% 3.1416   pi: not predefined
 {Sqrt 81.}         %% 9.0      square root; expects a float
 {Log 2.7183}       %% 1.0      natural logarithm
 {Abs ~1}           %% 1        absolute value; expects a float or an integer
 {Floor 1.999}      %% 1.0      floor; expects and returns a float
 {Ceil 1.999}       %% 2.0      ceiling; expects and returns a float
 {Pow 2 3}          %% 8        power; both arguments must be of the same type
]
Show}</lang>

Perl

<lang perl>use POSIX; # for floor() and ceil()

exp(1); # e 4 * atan2(1, 1); # pi sqrt($x); # square root log($x); # natural logarithm; log10() available in POSIX module exp($x); # exponential abs($x); # absolute value floor($x); # floor ceil($x); # ceiling $x ** $y; # power</lang>

Perl 6

Works with: Rakudo version #22 "Thousand Oaks"

<lang perl6>say e; # e say pi; # pi say sqrt 2; # Square root say log 2; # Natural logarithm say exp 42; # Exponentiation base e say abs -2; # Absolute value say floor pi; # Floor say ceiling pi; # Ceiling say 4**7; # Exponentiation</lang>

PHP

<lang php>M_E; //e M_PI; //pi sqrt(x); //square root log(x); //natural logarithm--log base 10 also available (log10) exp(x); //exponential abs(x); //absolute value floor(x); //floor ceil(x); //ceiling pow(x,y); //power</lang>

PL/I

<lang PL/I> /* e not available other than by using exp(1q0).*/ /* pi not available other than by using a trig function such as atan */ y = sqrt(x); y = log(x); y = log2(x); y = log10(x); y = exp(x); y = abs(x); y = floor(x); y = ceil(x); a = x**y; /* power */ /* extra functions: */ y = erf(x); /* the error function. */ y = erfc(x); /* the error function complemented. */ y = gamma (x); y = loggamma (x); </lang>

PicoLisp

PicoLisp has only limited floating point support (scaled bignum arithmetics). It can handle real numbers with as many positions after the decimal point as desired, but is practically limited by the precision of the C-library functions (about 16 digits). The default precision is six, and can be changed with 'scl': <lang PicoLisp>(scl 12) # 12 places after decimal point (load "@lib/math.l")

(prinl (format (exp 1.0) *Scl)) # e, exp (prinl (format pi *Scl)) # pi

(prinl (format (pow 2.0 0.5) *Scl)) # sqare root (prinl (format (sqrt (* 2.0 1.0)) *Scl))

(prinl (format (log 2.0) *Scl)) # logarithm (prinl (format (exp 4.0) *Scl)) # exponential

(prinl (format (abs -7.2) *Scl)) # absolute value (prinl (abs -123))

(prinl (format (pow 3.0 4.0) *Scl)) # power</lang> Output:

2.718281828459
3.141592653590
1.414213562373
1.414213562373
0.693147180560
54.598150033144
7.200000000000
123
81.000000000000

Pop11

<lang pop11>pi  ;;; Number Pi sqrt(x)  ;;; Square root log(x)  ;;; Natural logarithm exp(x)  ;;; Exponential function abs(x)  ;;; Absolute value x ** y  ;;; x to the power y</lang>

The number e is not provided directly, one has to compute 'exp(1)' instead. Also, floor and ceiling are not provided, one can define them using integer part:

<lang pop11>define floor(x);

   if x < 0 then
       -intof(x);
   else
       intof(x);
   endif;

enddefine;

define ceiling(x);

   -floor(-x);

enddefine;</lang>

PowerShell

Since PowerShell has access to .NET all this can be achieved using the .NET Base Class Library: <lang powershell>Write-Host ([Math]::E) Write-Host ([Math]::Pi) Write-Host ([Math]::Sqrt(2)) Write-Host ([Math]::Log(2)) Write-Host ([Math]::Exp(2)) Write-Host ([Math]::Abs(-2)) Write-Host ([Math]::Floor(3.14)) Write-Host ([Math]::Ceiling(3.14)) Write-Host ([Math]::Pow(2, 3))</lang>

PureBasic

<lang PureBasic>Debug #E Debug #PI Debug Sqr(f) Debug Log(f) Debug Exp(f) Debug Log10(f) Debug Abs(f) Debug Pow(f,f)</lang>

Python

<lang python>import math

math.e # e math.pi # pi math.sqrt(x) # square root (Also commonly seen as x ** 0.5 to obviate importing the math module) math.log(x) # natural logarithm math.log10(x) # base 10 logarithm math.exp(x) # exponential abs(x) # absolute value math.floor(x) # floor math.ceil(x) # ceiling x ** y # exponentiation pow(x,y,n) # exponentiation modulo n (useful in certain encryption/decryption algorithms)</lang>

R

<lang R>exp(1) # e pi # pi sqrt(x) # square root log(x) # natural logarithm log10(x) # base 10 logarithm log(x, y) # arbitrary base logarithm exp(x) # exponential abs(x) # absolute value floor(x) # floor ceiling(x) # ceiling x^y # power</lang>

Ruby

<lang ruby>Math::E #e Math::PI #pi Math.sqrt(x) #square root Math.log(x) #natural logarithm Math.log10(x) #base 10 logarithm Math.exp(x) #exponential x.abs #absolute value x.floor #floor x.ceil #ceiling x ** y #power</lang>

Scheme

<lang scheme>(sqrt x) ;square root (log x) ;natural logarithm (exp x) ;exponential (abs x) ;absolute value (floor x) ;floor (ceiling x) ;ceiling (expt x y) ;power</lang>

Slate

<lang slate>numerics E. numerics Pi. n sqrt. n log10. "base 10 logarithm" n ln. "natural logarithm" n log: m. "arbitrary base logarithm" n exp. "exponential" n abs. "absolute value" n floor. n ceiling. n raisedTo: anotherNumber</lang>

Smalltalk

<lang smalltalk>Float e. Float pi. aNumber sqrt. aNumber log. "base 10 logarithm" aNumber ln. "natural logarithm" aNumber exp. "exponential" aNumber abs. "absolute value" aNumber floor. aNumber ceiling. aNumber raisedTo: anotherNumber</lang>

Standard ML

<lang sml>Math.e; (* e *) Math.pi; (* pi *) Math.sqrt x; (* square root *) Math.ln x; (* natural logarithm--log base 10 also available (Math.log10) *) Math.exp x; (* exponential *) abs x; (* absolute value *) floor x; (* floor *) ceil x; (* ceiling *) Math.pow (x, y); (* power *)</lang>


Tcl

<lang tcl>expr {exp(1)}  ;# e expr {4 * atan(1)}  ;# pi -- also, simpler: expr acos(-1) expr {sqrt($x)}  ;# square root expr {log($x)}  ;# natural logarithm, also log10 expr {exp($x)}  ;# exponential expr {abs($x)}  ;# absolute value expr {floor($x)}  ;# floor expr {ceil($x)}  ;# ceiling expr {$x**$y}  ;# power, also pow($x,$y)</lang>

TI-89 BASIC

Mathematical TI-89 Notes
(U+212F SCRIPT SMALL E)
π (U+03C0 GREEK SMALL LETTER PI)
√(x) (U+221A SQUARE ROOT)
ln(x)
log(x)
log(b, x) The optional base argument comes first
floor(x)
ceiling(x)
x^y