Jump to content

Real constants and functions: Difference between revisions

no edit summary
No edit summary
Line 14:
=={{header|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
Line 24:
S'ceiling(x) -- Produces the ceiling of an instance of subtype S
x**y -- x raised to the y power
</adalang>
=={{header|ALGOL 68}}==
<pre>
Line 49:
=={{header|BASIC}}==
{{works with|QuickBasic|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</qbasiclang>
 
=={{header|C}}==
Most of the following functions take a double.
<lang c>#include <math.h>
 
M_E; /* e - not standard but offered by most implementations */
Line 69:
floor(x); /* floor */
ceil(x); /* ceiling */
pow(x,y); /* power */</clang>
 
=={{header|Common Lisp}}==
<lang lisp>pi ;pi constant
(sqrt x) ;square root
(log x) ;natural logarithm
Line 80:
(floor x) ;floor
(ceiling x) ;ceiling
(expt x y) ;power</lisplang>
 
=={{header|D}}==
<lang d>import std.math ; // need to import this module
E // Euler's number
PI // pi constant
Line 94:
floor(x) // floor
ceil(x) // ceiling
pow(x,y) // power</dlang>
=={{header|E}}==
 
Line 182:
=={{header|Java}}==
All of these functions are in Java's <tt>Math</tt> 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)
Line 190:
Math.floor(x); //floor
Math.ceil(x); //ceiling
Math.pow(x,y); //power</javalang>
 
=={{header|JavaScript}}==
Line 243:
=={{header|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 *)
Line 250:
floor x;; (* floor *)
ceil x;; (* ceiling *)
x ** y; (* power *)</ocamllang>
 
=={{header|Perl}}==
<lang perl>use POSIX;
 
exp(1); # e
Line 263:
POSIX::floor($x); # floor
POSIX::ceil($x); # ceiling
$x**$y; # power</perllang>
 
=={{header|PHP}}==
<lang php>M_E; //e
M_PI; //pi
sqrt(x); //square root
Line 274:
floor(x); //floor
ceil(x); //ceiling
pow(x,y); //power</phplang>
 
=={{header|Pop11}}==
Line 306:
 
=={{header|Python}}==
<lang python>import math
 
math.e # e
Line 318:
math.ceil(x) # ceiling
x ** y # exponentiation (and used with an exponent of 0.5 for square roots)
</pythonlang>
 
=={{header|Ruby}}==
<lang ruby>Math::E #e
Math::PI #pi
Math.sqrt(x) #square root
Line 330:
x.floor #floor
x.ceil #ceiling
x ** y #power</rubylang>
 
=={{header|Scheme}}==
<lang scheme>(sqrt x) ;square root
(log x) ;natural logarithm
(exp x) ;exponential
Line 339:
(floor x) ;floor
(ceiling x) ;ceiling
(expt x y) ;power</schemelang>
Cookies help us deliver our services. By using our services, you agree to our use of cookies.