Real constants and functions: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 23:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">math:e // e
math:pi // pi
sqrt(x) // square root
Line 32:
floor(x) // floor
ceil(x) // ceiling
x ^ y // exponentiation</langsyntaxhighlight>
 
=={{header|6502 Assembly}}==
Line 38:
Absolute value can be handled like so:
 
<langsyntaxhighlight lang="6502asm">GetAbs: ;assumes value we want to abs() is loaded into accumulator
eor #$ff
clc
adc #1
rts</langsyntaxhighlight>
 
 
Line 48:
Only the last three are available as built in functions.
 
<langsyntaxhighlight Lisplang="lisp">(floor 15 2) ;; This is the floor of 15/2
(ceiling 15 2)
(expt 15 2) ;; 15 squared</langsyntaxhighlight> =={{header|ACL2}}==
Only the last three are available as built in functions.
 
Line 56:
define them using integer part:
 
<langsyntaxhighlight lang="pop11">define floor(x);
if x < 0 then
-intof(x);
Line 66:
define ceiling(x);
-floor(-x);
enddefine;</langsyntaxhighlight>
 
=={{header|Action!}}==
Line 72:
{{libheader|Action! Tool Kit}}
{{libheader|Action! Real Math}}
<langsyntaxhighlight Actionlang="action!">INCLUDE "H6:REALMATH.ACT"
 
PROC Euler(REAL POINTER e)
Line 154:
PutE()
PrintE("There is no support in Action! for pi.")
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Real_constants_and_functions.png Screenshot from Atari 8-bit computer]
Line 176:
=={{header|ActionScript}}==
Actionscript has all the functions and constants mentioned in the task, available in the Math class.
<langsyntaxhighlight ActionScriptlang="actionscript">Math.E; //e
Math.PI; //pi
Math.sqrt(u); //square root of u
Line 184:
Math.floor(u);//floor of u
Math.ceil(u); //ceiling of u
Math.pow(u,v);//u to the power of v</langsyntaxhighlight>
The Math class also contains several other constants.
<langsyntaxhighlight ActionScriptlang="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</langsyntaxhighlight>
 
=={{header|Ada}}==
Most of the constants and functions used in this task are defined in the pre-defined Ada package Ada.Numerics.Elementary_Functions.
<langsyntaxhighlight lang="ada">Ada.Numerics.e -- Euler's number
Ada.Numerics.pi -- pi
sqrt(x) -- square root
Line 203:
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</langsyntaxhighlight>
 
=={{header|Aime}}==
<langsyntaxhighlight lang="aime"># e
exp(1);
# pi
Line 217:
floor(x);
ceil(x);
pow(x, y);</langsyntaxhighlight>
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">REAL x:=exp(1), y:=4*atan(1);
printf(($g(-8,5)"; "$,
exp(1), # e #
Line 232:
-ENTIER -x, # ceiling #
x ** y # power #
))</langsyntaxhighlight>
{{out}}
<pre> 2.71828; 3.14159; 1.64872; 0.43429; 1.00000; 15.15426; 2.71828; 2.00000; 3.00000; 23.14069; </pre>
Line 241:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin
real t, u;
t := 10;
Line 257:
% the raise-to-the-power operator is "**" - it only allows integers for the power %
write( " pi cubed: ", pi ** 3 ) % use exp( ln( x ) * y ) for general x^y %
end.</langsyntaxhighlight>
 
=={{header|ARM Assembly}}==
 
{{omit from|ARM Assembly}}
<syntaxhighlight lang="text">
/* functions not availables */
</syntaxhighlight>
</lang>
 
=={{header|Arturo}}==
<langsyntaxhighlight lang="rebol">print ["Euler:" e]
print ["Pi:" pi]
 
Line 277:
print ["floor 23.536:" floor 23.536]
print ["ceil 23.536:" ceil 23.536]
print ["2 ^ 8:" 2 ^ 8]</langsyntaxhighlight>
 
{{out}}
Line 293:
 
=={{header|Asymptote}}==
<langsyntaxhighlight Asymptotelang="asymptote">real e = exp(1); // e not available
write("e = ", e);
write("pi = ", pi);
Line 310:
write("ceil = ", ceil(-e)); // ceiling
write("power = ", x ^ y); // power
write("power = ", x ** y); // power</langsyntaxhighlight>
{{out}}
<pre>e = 2.71828182845905
Line 328:
=={{header|AutoHotkey}}==
The following math functions are built into AutoHotkey:
<langsyntaxhighlight lang="autohotkey">Sqrt(Number) ; square root
Log(Number) ; logarithm (base 10)
Ln(Number) ; natural logarithm (base e)
Line 335:
Floor(Number) ; floor
Ceil(Number) ; ceiling
x**y ; x to the power y</langsyntaxhighlight>
No mathematical constants are built-in, but they can all be calculated:
<langsyntaxhighlight lang="autohotkey">e:=exp(1)
pi:=2*asin(1)</langsyntaxhighlight>
The following are additional trigonometric functions that are built into the AutoHotkey language:
<langsyntaxhighlight lang="autohotkey">Sin(Number) ; sine
Cos(Number) ; cosine
Tan(Number) ; tangent
ASin(Number) ; arcsine
ACos(Number) ; arccosine
ATan(Number) ; arctangent</langsyntaxhighlight>
 
=={{header|AWK}}==
Awk has square root, logarithm, exponential and power.
 
<langsyntaxhighlight lang="awk">BEGIN {
print sqrt(2) # square root
print log(2) # logarithm base e
Line 356:
print 2 ^ -3.4 # power
}
# outputs 1.41421, 0.693147, 7.38906, 0.0947323</langsyntaxhighlight>
 
<blockquote style="font-size: smaller;">'''Power's note:'''
Line 367:
Awk misses e, pi, absolute value, floor and ceiling; but these are all easy to implement:
 
<langsyntaxhighlight lang="awk">BEGIN {
E = exp(1)
PI = atan2(0, -1)
Line 393:
print ceil(-3.4) # ceiling
}
# outputs 2.71828, 3.14159, 3.4, -4, -3</langsyntaxhighlight>
 
=={{header|Axe}}==
Line 400:
 
To take the square root of an integer X:
<syntaxhighlight lang ="axe">√(X)</langsyntaxhighlight>
 
To take the square root of an 8.8 fixed-point number Y:
<syntaxhighlight lang ="axe">√(Y)ʳ</langsyntaxhighlight>
 
To take the base-2 logarithm of an integer X:
<syntaxhighlight lang ="axe">ln(X)</langsyntaxhighlight>
 
To take 2 raised to an integer X: (Note that the base is not Euler's number)
<syntaxhighlight lang ="axe">e^(X)</langsyntaxhighlight>
 
To take the absolute value of a signed integer X:
<syntaxhighlight lang ="axe">abs(X)</langsyntaxhighlight>
 
=={{header|BASIC}}==
{{works with|QuickBasic|4.5}}
<langsyntaxhighlight 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</langsyntaxhighlight>
 
==={{header|IS-BASIC}}===
<langsyntaxhighlight ISlang="is-BASICbasic">100 LET X=2:LET Y=5
110 PRINT EXP(1) ! value of e
120 PRINT PI ! value of Pi
Line 443:
270 PRINT MAX(X,Y) ! the bigger number of x and y
280 PRINT EPS(X) ! the smallest quantity that can be added to or subtracted from x to make the interpreter register a change in the value of x
290 PRINT INF ! The largest positive number the tinterpreter can handle. This number is 9.999999999*10^62</langsyntaxhighlight>
 
==={{header|Sinclair ZX81 BASIC}}===
Line 449:
 
Base of the natural logarithm:
<syntaxhighlight lang ="basic">EXP 1</langsyntaxhighlight>
 
<math>\pi</math>:
<syntaxhighlight lang ="basic">PI</langsyntaxhighlight>
 
Square root:
<syntaxhighlight lang ="basic">SQR X</langsyntaxhighlight>
 
Natural logarithm:
<syntaxhighlight lang ="basic">LN X</langsyntaxhighlight>
 
Exponential:
<syntaxhighlight lang ="basic">EXP X</langsyntaxhighlight>
 
Absolute value:
<syntaxhighlight lang ="basic">ABS X</langsyntaxhighlight>
 
Floor:
<syntaxhighlight lang ="basic">INT X</langsyntaxhighlight>
(NB. Although this function is called <code>INT</code>, it corresponds to <code>floor</code>: e.g. <code>INT -3.1</code> returns -4 not -3.)
 
Line 474:
 
Power:
<syntaxhighlight lang ="basic">X**Y</langsyntaxhighlight>
NB. Both <math>x</math> and <math>y</math> can be real numbers.
 
==={{header|BBC BASIC}}===
<langsyntaxhighlight lang="bbcbasic"> e = EXP(1)
Pi = PI
Sqr2 = SQR(2)
Line 491:
DEF FNceil(n) = INT(n) - (INT(n) <> n)
</syntaxhighlight>
</lang>
 
=={{header|BASIC256}}==
<langsyntaxhighlight lang="basic256">e = exp(1) # e not available
print "e = "; e
print "PI = "; PI
Line 509:
print "floor = "; floor(-e) # floor
print "ceil = "; ceil(-e) # ceiling
print "power = "; x ^ y # power</langsyntaxhighlight>
{{out}}
<pre>e = 2.71828182846
Line 526:
The language has square root and power, but power only works if the exponent is an integer.
 
<langsyntaxhighlight lang="bc">scale = 6
sqrt(2) /* 1.414213 square root */
4.3 ^ -2 /* .054083 power (integer exponent) */</langsyntaxhighlight>
 
The standard library has natural logarithm and exponential functions. It can calculate e and pi: e comes from the exponential function, while pi is four times the arctangent of one. The usual formulas can calculate the powers with fractional exponents, and the logarithms with any base.
 
{{libheader|bc -l}}
<langsyntaxhighlight lang="bc">scale = 6
l(2) /* .693147 natural logarithm */
e(2) /* 7.389056 exponential */
Line 543:
 
e(l(2) * -3.4) /* .094734 2 to the power of -3.4 */
l(1024) / l(2) /* 10.000001 logarithm base 2 of 1024 */</langsyntaxhighlight>
 
The missing functions are absolute value, floor and ceiling. You can implement these functions, if you know what to do.
 
{{trans|AWK}}
<langsyntaxhighlight lang="bc">/* absolute value */
define v(x) {
if (x < 0) return (-x)
Line 582:
v(-3.4) /* 3.4 absolute value */
f(-3.4) /* -4 floor */
g(-3.4) /* -3 ceiling */</langsyntaxhighlight>
 
=={{header|blz}}==
The constant e
<syntaxhighlight lang ="blz">{e}</langsyntaxhighlight>
 
The constant pi
<syntaxhighlight lang ="blz">{pi}</langsyntaxhighlight>
 
Square root
<syntaxhighlight lang ="blz">x ** 0.5</langsyntaxhighlight>
 
Logarithm (base n)
<syntaxhighlight lang ="blz">x __ n</langsyntaxhighlight>
 
Exponential
<syntaxhighlight lang ="blz">{e} ** x</langsyntaxhighlight>
 
Absolute Value
<syntaxhighlight lang ="blz">abs(x)</langsyntaxhighlight>
 
Floor
<syntaxhighlight lang ="blz">floor(x)</langsyntaxhighlight>
 
Ceiling
<syntaxhighlight lang ="blz">ceil(x)</langsyntaxhighlight>
 
Power x to the y
<syntaxhighlight lang ="blz">x ** y</langsyntaxhighlight>
 
=={{header|Bracmat}}==
Bracmat has no real number type, but the constants <code>e</code> and <code>pi</code>, together with <code>i</code> can be used as symbols with the intended mathematical meaning in exponential functions.
For example, differentiation <code>10^x</code> to <code>x</code>
<langsyntaxhighlight lang="bracmat">x \D (10^x) { \D is the differentiation operator }</langsyntaxhighlight>
has the result
<langsyntaxhighlight lang="bracmat">10^x*e\L10 { \L is the logarithm operator }</langsyntaxhighlight>
Likewise <code>e^(i*pi)</code> evaluates to <code>-1</code> and <code>e^(1/2*i*pi)</code> evaluates to <code>i</code>.
 
Line 635:
=={{header|C}}==
Most of the following functions take a double.
<langsyntaxhighlight lang="c">#include <math.h>
 
M_E; /* e - not standard but offered by most implementations */
Line 646:
floor(x); /* floor */
ceil(x); /* ceiling */
pow(x,y); /* power */</langsyntaxhighlight>
 
To access the M_PI, etc. constants in Visual Studio, you may need to add the line <code>#define _USE_MATH_DEFINES</code> before the <code>#include <math.h></code>.
 
=={{header|C sharp}}==
<langsyntaxhighlight lang="csharp">using System;
 
class Program {
Line 666:
Console.WriteLine(Math.Pow(2, 5)); // Exponentiation
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
=== using Math macros ===
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <cmath>
 
Line 697:
<< "\nceiling(4.5) = " << std::ceil(4.5)
<< "\npi^2 = " << std::pow(pi,2.0) << std::endl;
}</langsyntaxhighlight>
=== using Boost ===
{{libheader|Boost}}
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <iomanip>
#include <cmath>
Line 718:
<< "\nfloor(4.5) = " << std::floor(4.5)
<< "\nceiling(4.5) = " << std::ceil(4.5) << std::endl;
}</langsyntaxhighlight>
{{out}}
<pre>e = 2.71828182845904509
Line 736:
=={{header|Clojure}}==
{{trans|Java}} which is directly available.
<langsyntaxhighlight lang="lisp">(Math/E); //e
(Math/PI); //pi
(Math/sqrt x); //square root--cube root also available (cbrt)
Line 744:
(Math/floor x); //floor
(Math/ceil x); //ceiling
(Math/pow x y); //power</langsyntaxhighlight>
 
Clojure does provide arbitrary precision versions as well:
 
<langsyntaxhighlight 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) </langsyntaxhighlight>
 
.. and as multimethods that can be defined for any type (e.g. complex numbers).
 
<langsyntaxhighlight lang="lisp">(ns user (:require [clojure.contrib.generic.math-functions :as generic]))
(generic/sqrt x)
(generic/log x)
Line 764:
(generic/floor x)
(generic/ceil x)
(generic/pow x y)</langsyntaxhighlight>
 
=={{header|COBOL}}==
Everything that follows can take any number (except for <code>SQRT</code> which expects a non-negative number).
The task constants and (intrinsic) functions:
<langsyntaxhighlight lang="cobol">E *> e
PI *> Pi
SQRT(n) *> Sqaure root
Line 781:
MOVE INTEGER(N) TO Result
*> There is no pow function, although the COMPUTE verb does have an exponention operator.
COMPUTE Result = N ** 2 </langsyntaxhighlight>
COBOL also has the following extra mathematical functions:
<langsyntaxhighlight lang="cobol">FACTORIAL(n) *> Factorial
EXP10(n) *> 10 to the nth power
*> Trigonometric functions, including inverse ones, named as would be expected.</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
In Lisp we should really be talking about numbers rather than the type <code>real</code>. The types <code>real</code> and <code>complex</code> are subtypes of <code>number</code>. Math operations that accept or produce complex numbers generally do.
<langsyntaxhighlight lang="lisp">
(exp 1) ; e (Euler's number)
pi ; pi constant
Line 800:
(ceiling x) ; ceiling: restricted to real, two valued (second value gives residue)
(expt x y) ; power
</syntaxhighlight>
</lang>
 
=={{header|Crystal}}==
<langsyntaxhighlight lang="ruby">x = 3.25
y = 4
 
Line 823:
puts exp(x) # puts Math.exp(x) -- exponential
puts E**x # puts Math::E**x -- same
</syntaxhighlight>
</lang>
 
{{0ut}}<pre>
Line 843:
 
=={{header|D}}==
<langsyntaxhighlight lang="d">import std.math ; // need to import this module
E // Euler's number
PI // pi constant
Line 854:
floor(x) // floor
ceil(x) // ceiling
pow(x,y) // power</langsyntaxhighlight>
 
=={{header|Delphi}}==
Delphi supports all basic Standard Pascal (ISO 7185) functions shown in [[#Pascal|§&nbsp;Pascal]].
Furthermore, the following is possible, too:
<langsyntaxhighlight Delphilang="delphi">Pi; // π (Pi)
LogN(BASE, x) // log of x for a specified base
Log2(x) // log of x for base 2
Line 865:
Floor(x); // floor
Ceil(x); // ceiling
Power(x, y); // power</langsyntaxhighlight>
Note, <tt>Log</tt>, <tt>Floor</tt>, <tt>Ceil</tt> and <tt>Power</tt> are from the <tt>Math</tt> unit, which needs to be listed in the <tt>uses</tt>-clauses.
 
Line 872:
 
=={{header|E}}==
<langsyntaxhighlight lang="e">? 1.0.exp()
# value: 2.7182818284590455
 
Line 897:
 
? 10 ** 6
# value: 1000000</langsyntaxhighlight>
 
=={{header|Elena}}==
ELENA 4.x :
<langsyntaxhighlight lang="elena">import system'math;
import extensions;
Line 916:
console.printLine(10.0r.ceil()); //Ceiling
console.printLine(2.power(5)); //Exponentiation
}</langsyntaxhighlight>
 
=={{header|Elixir}}==
<langsyntaxhighlight lang="elixir">defmodule Real_constants_and_functions do
def main do
IO.puts :math.exp(1) # e
Line 934:
end
 
Real_constants_and_functions.main</langsyntaxhighlight>
 
=={{header|Elm}}==
The following are all in the Basics module, which is imported by default:
<langsyntaxhighlight lang="elm">e -- e
pi -- pi
sqrt x -- square root
Line 946:
floor x -- floor
ceiling x -- ceiling
2 ^ 3 -- power</langsyntaxhighlight>
 
=={{header|Erlang}}==
<langsyntaxhighlight lang="erlang">% Implemented by Arjun Sunel
-module(math_constants).
-export([main/0]).
Line 984:
false -> T + 1
end.
</syntaxhighlight>
</lang>
{{out}}
<pre>2.718281828459045
Line 1,001:
 
=={{header|ERRE}}==
<langsyntaxhighlight ERRElang="erre">PROGRAM R_C_F
 
FUNCTION CEILING(X)
Line 1,028:
PRINT(CEILING(X)) ! ceiling
PRINT(X^Y) ! power
END PROGRAM</langsyntaxhighlight>
{{out}}
<pre> 2.718282
Line 1,045:
=={{header|F Sharp|F#}}==
{{trans|C#|C sharp}}
<langsyntaxhighlight lang="fsharp">open System
 
let main _ =
Line 1,059:
Console.WriteLine(Math.Pow(2.0, 5.0)); // Exponentiation
 
0</langsyntaxhighlight>
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">e ! e
pi ! π
sqrt ! square root
Line 1,072:
truncate ! remove the fractional part (i.e. round towards 0)
round ! round to next whole number
^ ! power</langsyntaxhighlight>
 
=={{header|Fantom}}==
Line 1,078:
The <code>Float</code> class holds 64-bit floating point numbers, and contains most of the useful mathematical functions. A floating point number must be specified when entered with the suffix 'f', e.g. <code>9f</code>
 
<langsyntaxhighlight lang="fantom">
Float.e
Float.pi
Line 1,090:
3.2f.round // nearest Int
3f.pow(2f) // power
</syntaxhighlight>
</lang>
 
Note, . binds more tightly than -, so use brackets around negative numbers:
Line 1,102:
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">1e fexp fconstant e
0e facos 2e f* fconstant pi \ predefined in gforth
fsqrt ( f -- f )
Line 1,110:
floor ( f -- f ) \ round towards -inf
: ceil ( f -- f ) fnegate floor fnegate ; \ not standard, though fround is available
f** ( f e -- f^e )</langsyntaxhighlight>
 
=={{header|Fortran}}==
<langsyntaxhighlight lang="fortran"> e ! Not available. Can be calculated EXP(1.0)
pi ! Not available. Can be calculated 4.0*ATAN(1.0)
SQRT(x) ! square root
Line 1,122:
FLOOR(x) ! floor - Fortran 90 or later only
CEILING(x) ! ceiling - Fortran 90 or later only
x**y ! x raised to the y power</langsyntaxhighlight>
 
4*ATAN(1.0) will be calculated in single precision, likewise EXP(1.0) (not EXP(1), because 1 is an integer) and although double precision functions can be named explicitly, 4*DATAN(1.0) will be rejected because 1.0 is in single precision and DATAN expects double. Thus, 4*DATAN(1.0D0) or 4*DATAN(1D0) will do, as the D in the exponent form specifies double precision. Whereupon, the generic names can be returned to: 4*ATAN(1D0). Some systems go further and offer quadruple precision. Others allow that all constants will be deemed double precision as a compiler option.
Line 1,129:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
#Include "crt/math.bi"
Line 1,143:
Print ceil(-2.5) '' ceiling function from C runtime library
Print 2.5 ^ 3.5 '' exponentiation operator built into FB
Sleep </langsyntaxhighlight>
 
{{out}}
Line 1,164:
=={{header|Frink}}==
All of the following operations work for any numerical type, including rational numbers, complex numbers and intervals of real numbers.
<langsyntaxhighlight lang="frink">
e
pi, π // Unicode can also be written in ASCII programs as \u03C0
Line 1,175:
ceil[x] // Except for complex numbers where there's no good interpretation.
x^y
</syntaxhighlight>
</lang>
 
=={{header|FutureBasic}}==
<langsyntaxhighlight lang="futurebasic">window 1
 
text ,,,,, 60// set tab width
Line 1,193:
print @"power:", 1.23 ^ 4
 
HandleEvents</langsyntaxhighlight>
Output:
<pre>
Line 1,209:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,262:
fmt.Println("x:", x)
fmt.Println("abs(x):", y.Abs(x))
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,292:
 
In addition to the java.lang.Math.abs() method, each numeric type has an abs() method, which can be invoked directly on the number:
<langsyntaxhighlight lang="groovy">println ((-22).abs())</langsyntaxhighlight>
{{out}}
<pre>22</pre>
Line 1,299:
 
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:
<syntaxhighlight lang ="groovy">println 22**3.5</langsyntaxhighlight>
{{out}}
<pre>49943.547010599876</pre>
Line 1,305:
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.
<langsyntaxhighlight lang="groovy">println ((-22)**3.5)</langsyntaxhighlight>
{{out}}
<pre>NaN</pre>
Line 1,314:
=={{header|Haskell}}==
The operations are defined for the various numeric typeclasses, as defined in their type signature.
<langsyntaxhighlight lang="haskell">exp 1 -- Euler number
pi -- pi
sqrt x -- square root
Line 1,324:
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)</langsyntaxhighlight>
 
=={{header|HicEst}}==
Except for x^y, this is identical to Fortran:
<langsyntaxhighlight HicEstlang="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
Line 1,338:
CEILING(x) ! ceiling
x**y ! x raised to the y power
x^y ! same as x**y</langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
<langsyntaxhighlight Iconlang="icon">link numbers # for floor and ceil
 
procedure main()
Line 1,355:
write("ceil(-2.2)=",ceil(-2.2))
write("power: 3^3=",3^3)
end</langsyntaxhighlight>
{{libheader|Icon Programming Library}}
[http://www.cs.arizona.edu/icon/library/src/procs/numbers.icn numbers provides floor and ceiling]
Line 1,373:
=={{header|J}}==
The examples below require arguments (x and y) to be numeric nouns.
<langsyntaxhighlight 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.
Line 1,386:
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</langsyntaxhighlight>
 
=={{header|Java}}==
All of these functions are in Java's <tt>Math</tt> class which, does not require any imports:
<langsyntaxhighlight lang="java">Math.E; //e
Math.PI; //pi
Math.sqrt(x); //square root--cube root also available (cbrt)
Line 1,398:
Math.floor(x); //floor
Math.ceil(x); //ceiling
Math.pow(x,y); //power</langsyntaxhighlight>
 
=={{header|JavaScript}}==
<langsyntaxhighlight lang="javascript">Math.E
Math.PI
Math.sqrt(x)
Line 1,409:
Math.floor(x)
Math.ceil(x)
Math.pow(x,y)</langsyntaxhighlight>
 
=={{header|jq}}==
Line 1,415:
In jq, "." refers to the output coming from the left in the pipeline.
 
In the following, comments appear after the "#":<langsyntaxhighlight lang="jq">
1 | exp # i.e. e
1 | atan * 4 # i.e. π
Line 1,424:
floor
ceil # requires jq >= 1.5
pow(x; y) # requires jq >= 1.5</langsyntaxhighlight>
 
=={{header|Jsish}}==
<langsyntaxhighlight lang="javascript">/* real constants and functions, in JSI */
var x, y;
 
Line 1,469:
Math.pow(x,y) ==> 100000
=!EXPECTEND!=
*/</langsyntaxhighlight>
 
{{out}}
Line 1,494:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">e
π, pi
sqrt(x)
Line 1,502:
floor(x)
ceil(x)
x^y</langsyntaxhighlight>
Note that Julia supports Unicode identifiers, and allows either <code>π</code> or <code>pi</code> for that constant.
 
Line 1,508:
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.0.6
 
fun main(args: Array<String>) {
Line 1,521:
println(Math.ceil(-2.5)) // ceiling
println(Math.pow(2.5, 3.5)) // power
}</langsyntaxhighlight>
 
{{out}}
Line 1,538:
 
=={{header|Lambdatalk}}==
<langsyntaxhighlight lang="scheme">
{E} -> 2.718281828459045
{PI} -> 3.141592653589793
Line 1,548:
{ceil -2.5} -> -2
{pow 2.5 3.5} -> 24.705294220065465
</syntaxhighlight>
</lang>
 
=={{header|Lasso}}==
<syntaxhighlight lang="lasso">//e
<lang Lasso>//e
define e => 2.7182818284590452
 
Line 1,566:
1.64->floor
1.64->ceil
1.64->pow(10.0)</langsyntaxhighlight>
 
=={{header|Liberty BASIC}}==
Line 1,574:
<br>
e & pi not available- calculate as shown.
<syntaxhighlight lang="lb">
<lang lb>
print exp( 1) ' e not available
print 4 *atn( 1) ' pi not available
Line 1,607:
end if
end function
</syntaxhighlight>
</lang>
 
=={{header|Lingo}}==
<langsyntaxhighlight lang="lingo">the floatPrecision = 8
 
-- e (base of the natural logarithm)
Line 1,656:
-- power
put power(2, 8)
-- 256.00000000</langsyntaxhighlight>
 
=={{header|LiveCode}}==
LC 7.1+, prior to this floor & ceil were not built-in.
<langsyntaxhighlight LiveCodelang="livecode">e‬: exp(1)
pi: pi
square root: sqrt(x)
Line 1,668:
floor: floor(x)
ceiling: ceil(x)
power: x^y</langsyntaxhighlight>
 
=={{header|Logo}}==
{{works with|UCB Logo}}
<langsyntaxhighlight lang="logo">make "e exp 1
make "pi 2*(RADARCTAN 0 1)
sqrt :x
Line 1,678:
exp :x
; there is no standard abs, floor, or ceiling; only INT and ROUND.
power :x :y</langsyntaxhighlight>
 
=={{header|Logtalk}}==
<langsyntaxhighlight lang="logtalk">
:- object(constants_and_functions).
 
Line 1,698:
 
:- end_object.
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,715:
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">math.exp(1)
math.pi
math.sqrt(x)
Line 1,724:
math.floor(x)
math.ceil(x)
x^y</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Checkit {
Def exp(x)= 2.71828182845905^x
Line 1,766:
}
Checkit
</syntaxhighlight>
</lang>
 
=={{header|Maple}}==
<langsyntaxhighlight Maplelang="maple">> abs(ceil(floor(ln(exp(1)^sqrt(exp(Pi*I)+1)))));
0</langsyntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">E
<lang Mathematica>E
Pi
Sqrt[x]
Line 1,782:
Floor[x]
Ceiling[x]
Power[x, y]</langsyntaxhighlight>
Where x is the number, and b the base.
Exp[x] can also be inputted as E^x or E<sup>x</sup> and Power[x,y] can be also inputted as x^y or x<sup>y</sup>. 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:
<langsyntaxhighlight Mathematicalang="mathematica">Log[1.23] => 0.207014
Log[10] => Log[10]
Log[10,100] => 2
Line 1,800:
Sqrt[-4] => 2I
Exp[2] => E^2
Exp[Log[4]] => 4</langsyntaxhighlight>
 
=={{header|MATLAB}} / {{header|Octave}}==
<langsyntaxhighlight MATLABlang="matlab">exp(1) % e
pi % pi
sqrt(x) % square root
Line 1,813:
floor(x) % floor
ceil(x) % ceiling
x^y % power</langsyntaxhighlight>
 
=={{header|MAXScript}}==
<langsyntaxhighlight lang="maxscript">e -- Euler's number
pi -- pi
log x -- natural logarithm
Line 1,824:
floor x -- floor
ceil x -- ceiling
pow x y -- power</langsyntaxhighlight>
 
=={{header|Mercury}}==
<syntaxhighlight lang="text">
math.pi % Pi.
math.e % Euler's number.
Line 1,839:
math.floor(X) % Floor of X.
math.ceiling(X) % Ceiling of X.
math.pow(X, Y) % X raised to the power of Y.</langsyntaxhighlight>
 
=={{header|Metafont}}==
<langsyntaxhighlight 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
Line 1,856:
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</langsyntaxhighlight>
 
=={{header|min}}==
{{works with|min|0.19.3}}
<langsyntaxhighlight lang="min">e ; e
pi ; π
sqrt ; square root
Line 1,871:
trunc ; remove the fractional part (i.e. round towards 0)
round ; round number to nth decimal place
pow ; power</langsyntaxhighlight>
 
=={{header|МК-61/52}}==
<syntaxhighlight lang="text">1 e^x С/П
 
пи С/П
Line 1,892:
x<0 14 ИП1 С/П ИП1 1 + С/П
 
x^y С/П</langsyntaxhighlight>
 
=={{header|Modula-3}}==
Line 1,898:
 
Note that all of these procedures (except the built ins) take <tt>LONGREAL</tt>s as their argument, and return <tt>LONGREAL</tt>s.
<langsyntaxhighlight lang="modula3">Math.E;
Math.Pi;
Math.sqrt(x);
Line 1,906:
FLOOR(x); (* Built in function. *)
CEILING(x); (* Built in function. *)
Math.pow(x, y);</langsyntaxhighlight>
 
=={{header|Neko}}==
<syntaxhighlight lang="actionscript">/**
<lang ActionScript>/**
Real constants and functions, in Neko
Tectonics:
Line 1,936:
$print("Floor(-2.2): ", math_floor(-2.2), "\n")
$print("Ceil(-2.2) : ", math_ceil(-2.2), "\n")
$print("Pow(2, 8) : ", math_pow(2, 8), "\n")</langsyntaxhighlight>
 
{{out}}
Line 1,953:
=={{header|NetRexx}}==
All the required constants and functions (and more) are in [[Java|Java's]] <tt>Math</tt> class. NetRexx also provides a limited set of built in numeric manipulation functions for it's Rexx object.
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary utf8
 
Line 2,002:
say Rexx(' Truncate' x 'by' y':').left(pad) x.trunc(y)
say Rexx(' Format (with rounding)' x 'by' y':').left(pad) x.format(y, 0)
</syntaxhighlight>
</lang>
 
{{out}}
Line 2,046:
 
=={{header|Nim}}==
<langsyntaxhighlight lang="nim">import math
 
var x, y = 12.5
Line 2,059:
echo floor(x)
echo ceil(x)
echo pow(x, y)</langsyntaxhighlight>
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">Float->Pi();
Float->E();
4.0->SquareRoot();
Line 2,070:
3.99->Floor();
3.99->Ceiling();
4.5->Ceiling(2.0);</langsyntaxhighlight>
 
=={{header|OCaml}}==
Unless otherwise noted, the following functions are for floats only:
<langsyntaxhighlight lang="ocaml">Float.pi (* pi *)
sqrt x (* square root *)
log x (* natural logarithm--log base 10 also available (log10) *)
Line 2,083:
ceil x (* ceiling *)
x ** y (* power *)
-. x (* negation for floats *)</langsyntaxhighlight>
 
=={{header|Octave}}==
<langsyntaxhighlight lang="octave">e % e
pi % pi
sqrt(pi) % square root
Line 2,094:
floor(pi) % floor
ceil(pi) % ceiling
e**pi % power</langsyntaxhighlight>
 
=={{header|Oforth}}==
 
<langsyntaxhighlight Oforthlang="oforth">import: math
 
: testReal
Line 2,121:
-2.4 ceil println
-3.9 ceil println
-5.5 ceil println ;</langsyntaxhighlight>
 
=={{header|ooRexx}}==
{{trans|NetRexx}}
{{uses from|OoRexx|RxMath}}
<langsyntaxhighlight ooRexxlang="oorexx">/* Rexx */
 
-- MathLoadFuncs & MathDropFuncs are no longer needed and are effectively NOPs
Line 2,183:
return arg(1)~trunc() + (arg(1) > 0) * (arg(1) \= arg(1)~trunc())
 
::requires 'RxMath' library</langsyntaxhighlight>
{{out}}
<pre>
Line 2,226:
 
=={{header|Oz}}==
<langsyntaxhighlight lang="oz">{ForAll
[
{Exp 1.} %% 2.7183 Euler's number: not predefined
Line 2,237:
{Pow 2 3} %% 8 power; both arguments must be of the same type
]
Show}</langsyntaxhighlight>
 
=={{header|PARI/GP}}==
<langsyntaxhighlight lang="parigp">[exp(1), Pi, sqrt(2), log(2), abs(2), floor(2), ceil(2), 2^3]</langsyntaxhighlight>
 
=={{header|Pascal}}==
''See also [[#Delphi|Delphi]] and [[#Free Pascal|Free Pascal]]''<br/>
Following functions are defined by ISO standard 7185, Standard “Unextended” Pascal, and supported by any processor:
<langsyntaxhighlight lang="pascal"> { Euler’s constant }
exp(1)
{ principal square root of `x` }
Line 2,254:
exp(x)
{ absolute value }
abs(x)</langsyntaxhighlight>
{{works with|Extended Pascal}}
Additionally, in Extended Pascal (ISO standard 10206) following operators and expressions can be used:
<langsyntaxhighlight lang="pascal"> { Pi }
2 * arg(cmplx(0.0, maxReal))
{ power, yields same data type as `base`, `exponent` has to be an `integer` }
Line 2,264:
{ `exponent` are automatically promoted to an approximate `real` value, result }
{ is `complex` if `base` is `complex`, otherwise a `real` value }
base ** exponent</langsyntaxhighlight>
<tt>Exp</tt>, <tt>sqrt</tt>, <tt>ln</tt>, and <tt>exp</tt> return <tt>real</tt> values, but a <tt>complex</tt> value if supplied with a <tt>complex</tt> value.
<tt>Abs</tt> returns an <tt>integer</tt> value if supplied with an <tt>integer</tt>, otherwise a <tt>real</tt> value.
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use POSIX; # for floor() and ceil()
 
exp(1); # e
Line 2,285:
 
use Math::Complex;
pi; # alternate way to get pi</langsyntaxhighlight>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #0000FF;">?</span><span style="color: #004600;">E</span> <span style="color: #000080;font-style:italic;">-- Euler number</span>
<span style="color: #0000FF;">?</span><span style="color: #004600;">PI</span> <span style="color: #000080;font-style:italic;">-- pi</span>
Line 2,304:
<span style="color: #0000FF;">?</span><span style="color: #004600;">INVLN10</span> <span style="color: #000080;font-style:italic;">-- displays 0.434..</span>
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">exp</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">/</span><span style="color: #004600;">INVLN10</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- displays 10.0</span>
<!--</langsyntaxhighlight>-->
 
=={{header|PHP}}==
<langsyntaxhighlight lang="php">M_E; //e
M_PI; //pi
sqrt(x); //square root
Line 2,315:
floor(x); //floor
ceil(x); //ceiling
pow(x,y); //power</langsyntaxhighlight>
 
=={{header|Picat}}==
<langsyntaxhighlight Picatlang="picat">main =>
println(math.e),
println(math.pi),
Line 2,339:
println(math.pi**math.e), % power
println(pow(math.pi,math.e)), % power
nl.</langsyntaxhighlight>
 
{{out}}
Line 2,367:
(about 16 digits). The default precision is six, and can be changed with
'[http://software-lab.de/doc/refS.html#scl scl]':
<langsyntaxhighlight PicoLisplang="picolisp">(scl 12) # 12 places after decimal point
(load "@lib/math.l")
 
Line 2,382:
(prinl (abs -123))
 
(prinl (format (pow 3.0 4.0) *Scl)) # power</langsyntaxhighlight>
{{out}}
<pre>2.718281828459
Line 2,395:
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">/* e not available other than by using exp(1q0).*/
/* pi not available other than by using a trig function such as: pi=4*atan(1) */
y = sqrt(x);
Line 2,410:
y = erfc(x); /* the error function complemented. */
y = gamma (x);
y = loggamma (x);</langsyntaxhighlight>
 
=={{header|Pop11}}==
<langsyntaxhighlight 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</langsyntaxhighlight>
 
The number e is not provided directly, one has to compute 'exp(1)'
Line 2,427:
=={{header|PowerShell}}==
Since PowerShell has access to .NET all this can be achieved using the .NET Base Class Library:
<langsyntaxhighlight lang="powershell">Write-Host ([Math]::E)
Write-Host ([Math]::Pi)
Write-Host ([Math]::Sqrt(2))
Line 2,435:
Write-Host ([Math]::Floor(3.14))
Write-Host ([Math]::Ceiling(3.14))
Write-Host ([Math]::Pow(2, 3))</langsyntaxhighlight>
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">Debug #E
Debug #PI
Debug Sqr(f)
Line 2,445:
Debug Log10(f)
Debug Abs(f)
Debug Pow(f,f)</langsyntaxhighlight>
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">import math
 
math.e # e
Line 2,463:
 
# The math module constants and functions can, of course, be imported directly by:
# from math import e, pi, sqrt, log, log10, exp, floor, ceil</langsyntaxhighlight>
 
=={{header|R}}==
<langsyntaxhighlight Rlang="r">exp(1) # e
pi # pi
sqrt(x) # square root
Line 2,476:
floor(x) # floor
ceiling(x) # ceiling
x^y # power</langsyntaxhighlight>
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">(exp 1) ; e
pi ; pi
(sqrt x) ; square root
Line 2,487:
(floor x) ; floor
(ceiling x) ; ceiling
(expt x y) ; power</langsyntaxhighlight>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>say e; # e
say π; # or pi # pi
say τ; # or tau # tau
Line 2,528:
say pi.ceiling; # Ceiling
 
say e ** π\i + 1 ≅ 0; # :-)</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 2,535:
REXX doesn't have any built-in (math) constants.
===abs===
<langsyntaxhighlight lang="rexx">a=abs(y) /*takes the absolute value of y.*/</langsyntaxhighlight>
===exponentiation (**)===
<langsyntaxhighlight lang="rexx">r=x**y /*REXX only supports integer powers.*/
/*Y may be negative, zero, positive.*/
/*X may be any real number. */</langsyntaxhighlight>
 
===ceiling===
A ceiling function for REXX:
<langsyntaxhighlight lang="rexx">
ceiling: procedure; parse arg x; t=trunc(x); return t+(x>0)*(x\=t)
</syntaxhighlight>
</lang>
 
===floor===
A floor function for REXX:
<langsyntaxhighlight lang="rexx">
floor: procedure; parse arg x; t=trunc(x); return t-(x<0)-(x\=t)
</syntaxhighlight>
</lang>
 
===sqrt (optimized)===
A [principal] square root (SQRT) function for REXX &nbsp; (with arbitrary precision):
<langsyntaxhighlight lang="rexx">/*──────────────────────────────────SQRT subroutine───────────────────────────*/
sqrt: procedure; parse arg x; if x=0 then return 0 /*handle 0 case.*/
if \datatype(x,'N') then return '[n/a]' /*Not Applicable ───if not numeric.*/
Line 2,581:
/* [↓] normalize √ ──► original digits*/
numeric digits d /* [↓] make answer complex if X < 0. */
return (g/1)i /*normalize, and add possible I suffix.*/</langsyntaxhighlight>
<langsyntaxhighlight lang="rexx"> ╔════════════════════════════════════════════════════════════════════╗
╔═╝ __ ╚═╗
║ √ ║
Line 2,607:
║ __ ║
╚═╗ √ ╔═╝
╚════════════════════════════════════════════════════════════════════╝</langsyntaxhighlight>
 
===sqrt (simple)===
<langsyntaxhighlight lang="rexx">/*──────────────────────────────────SQRT subroutine─────────────────────*/
sqrt: procedure; arg x /*a simplistic SQRT subroutine.*/
if x=0 then return 0 /*handle special case of zero. */
Line 2,623:
end /*forever*/ /* [↑] ···'til we run out of digs*/
numeric digits d /*restore the original precision.*/
return g/1 /*normalize to old precision (d).*/</langsyntaxhighlight>
 
===other===
Other mathematical-type functions supported are:
<langsyntaxhighlight lang="rexx">numeric digits ddd /*sets the current precision to DDD */
numeric fuzz fff /*arithmetic comparisons with FFF fuzzy*/
numeric form kkk /*exponential: scientific | engineering*/
Line 2,653:
bb=x2b(hhh) /*converts hexadecimal to binary (bits)*/
cc=x2c(hhh) /*converts hexadecimal to character. */
dd=x2d(hhh) /*converts hexadecimal to decimal. */</langsyntaxhighlight>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
See "Mathematical Functions" + nl
See "Sin(0) = " + sin(0) + nl
Line 2,702:
 
see "sqrt(16) = " + sqrt(16) + nl
</syntaxhighlight>
</lang>
 
=={{header|RLaB}}==
Line 2,709:
 
RLaB has a number of mathematical constants built-in within the list ''const''. These facilities are provided through the Gnu Science Library [[http://www.gnu.org/software/gsl]].
<langsyntaxhighlight RLaBlang="rlab">>> const
e euler ln10 ln2 lnpi
log10e log2e pi pihalf piquarter
rpi sqrt2 sqrt2r sqrt3 sqrtpi
tworpi</langsyntaxhighlight>
 
=== Physical Constants ===
Another list of physical constants and unit conversion factors exists and is called ''mks''.
Here the conversion goes between that particular unit and the equivalent unit in, one and only, metric system.
<langsyntaxhighlight RLaBlang="rlab">>> mks
F G J L N
Na R0 Ry Tsp V0
Line 2,741:
therm tntton ton torr toz
tsp uam ukgal ukton uston
week yd</langsyntaxhighlight>
 
=== Elementary Functions ===
<langsyntaxhighlight RLaBlang="rlab">>> x = rand()
>> sqrt(x)
2.23606798
Line 2,760:
5
>> x .^ 2
25</langsyntaxhighlight>
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">x.abs #absolute value
x.magnitude #absolute value
x.floor #floor
Line 2,776:
log10(x) #base 10 logarithm
exp(x) #exponential
</syntaxhighlight>
</lang>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">print "exp:";chr$(9); EXP(1)
print "PI:";chr$(9); 22/7
print "Sqr2:";chr$(9); SQR(2)
Line 2,787:
print "Floor:";chr$(9); INT(1.534)
print "ceil:";chr$(9); val(using("###",1.534))
print "Power:";chr$(9); 1.23^4</langsyntaxhighlight>
<pre>exp: 2.71828183
PI: 3.14285707
Line 2,799:
 
=={{header|Rust}}==
<langsyntaxhighlight lang="rust">use std::f64::consts::*;
 
fn main() {
Line 2,822:
 
assert_eq!(x, 4.0);
}</langsyntaxhighlight>
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">object RealConstantsFunctions extends App{
println(math.E) // e
println(math.Pi) // pi
Line 2,836:
println(math.ceil(-2.5)) // ceiling
println(math.pow(2.5, 3.5)) // power
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
<langsyntaxhighlight lang="scheme">(sqrt x) ;square root
(log x) ;natural logarithm
(exp x) ;exponential
Line 2,845:
(floor x) ;floor
(ceiling x) ;ceiling
(expt x y) ;power</langsyntaxhighlight>
 
=={{header|Seed7}}==
Line 2,875:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">Num.e # e
Num.pi # pi
x.sqrt # square root
Line 2,884:
x.floor # floor
x.ceil # ceiling
x**y # exponentiation</langsyntaxhighlight>
 
=={{header|Slate}}==
<langsyntaxhighlight lang="slate">numerics E.
numerics Pi.
n sqrt.
Line 2,897:
n floor.
n ceiling.
n raisedTo: anotherNumber</langsyntaxhighlight>
 
=={{header|Smalltalk}}==
<langsyntaxhighlight lang="smalltalk">Float e.
Float pi.
aNumber sqrt.
Line 2,909:
aNumber floor.
aNumber ceiling.
aNumber raisedTo: anotherNumber</langsyntaxhighlight>
 
=={{header|Sparkling}}==
<langsyntaxhighlight lang="sparkling">// e:
print(M_E);
 
Line 2,942:
 
// power
let eighty_one = pow(3, 4);</langsyntaxhighlight>
 
=={{header|Standard ML}}==
<langsyntaxhighlight lang="sml">Math.e; (* e *)
Math.pi; (* pi *)
Math.sqrt x; (* square root *)
Line 2,954:
ceil x; (* ceiling *)
Math.pow (x, y); (* power *)
~ x; (* negation *)</langsyntaxhighlight>
 
=={{header|Stata}}==
<langsyntaxhighlight lang="stata">scalar x=2
scalar y=3
di exp(1)
Line 2,969:
di floor(x)
di ceil(x)
di x^y</langsyntaxhighlight>
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">import Darwin
 
M_E // e
Line 2,982:
floor(x) // floor
ceil(x) // ceiling
pow(x,y) // power</langsyntaxhighlight>
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">expr {exp(1)} ;# e
expr {4 * atan(1)} ;# pi -- also, simpler: expr acos(-1)
expr {sqrt($x)} ;# square root
Line 2,993:
expr {floor($x)} ;# floor
expr {ceil($x)} ;# ceiling
expr {$x**$y} ;# power, also pow($x,$y)</langsyntaxhighlight>
The constants <math>e</math> and <math>\pi</math> are also available with high precision in a support library.
{{tcllib|math::constants}}
<langsyntaxhighlight lang="tcl">package require math::constants
math::constants::constants e pi
puts "e = $e, pi = $pi"</langsyntaxhighlight>
 
=={{header|TI-89 BASIC}}==
Line 3,025:
 
=={{header|True BASIC}}==
<langsyntaxhighlight lang="qbasic">FUNCTION floor(x)
IF x > 0 THEN
LET floor = INT(x)
Line 3,049:
PRINT "ceil = "; CEIL(x) ! ceiling
PRINT "power = "; x ^ y ! power
END</langsyntaxhighlight>
 
=={{header|UNIX Shell}}==
{{works with|ksh93}}
ksh93 exposes math functions from the C math library
<langsyntaxhighlight lang="bash">echo $(( exp(1) )) # e
echo $(( acos(-1) )) # PI
x=5
Line 3,068:
echo $(( ceil(x) )) # ceiling
x=10 y=3
echo $(( pow(x,y) )) # power</langsyntaxhighlight>
 
{{out}}
Line 3,084:
 
=={{header|Wren}}==
<langsyntaxhighlight lang="ecmascript">var e = 1.exp
 
System.print("e = %(e)")
Line 3,094:
System.print("floor(e) = %(e.floor)")
System.print("ceil(e) = %(e.ceil)")
System.print("pow(e, 2) = %(e.pow(2))")</langsyntaxhighlight>
 
{{out}}
Line 3,110:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">include c:\cxpl\codes; \intrinsic 'code' declarations
 
func real Power(X, Y); \X raised to the Y power
Line 3,135:
RlOut(0, float(fix(1.001+0.5))); CrLf(0); \ceiling rounds toward +infinity
RlOut(0, Power(sqrt(2.0), 4.0)); CrLf(0); \sqrt is an inline function and
] \ can be used for both reals & ints</langsyntaxhighlight>
 
{{out}}
Line 3,157:
 
=={{header|Yabasic}}==
<langsyntaxhighlight lang="yabasic">print "e = ", euler
print "pi = ", pi
Line 3,171:
print "ceil = ", ceil(-euler) // ceiling
print "power = ", x ^ y, " ", x ** y // power
end</langsyntaxhighlight>
{{out}}
<pre>e = 2.71828
Line 3,185:
 
=={{header|Zig}}==
<langsyntaxhighlight lang="zig">const std = @import("std");
 
pub fn main() void {
Line 3,198:
std.debug.print("ceil(x) = {d}\n", .{std.math.ceil(x)});
std.debug.print("pow(f64, -x, x) = {d}\n", .{std.math.pow(f64, -x, x)});
}</langsyntaxhighlight>
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">(0.0).e // Euler's number, a property of all floats
(0.0).e.pi // pi, yep, all floats
(2.0).sqrt() // square root
Line 3,210:
x.pow(y) // x raised to the y power
x.ceil() // ceiling
x.floor() // floor</langsyntaxhighlight>
 
{{omit from|GUISS}}
10,327

edits