Real constants and functions: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 14: | Line 14: | ||
=={{header|Ada}}== |
=={{header|Ada}}== |
||
Most of the constants and functions used in this task are defined in the pre-defined Ada package Ada.Numerics.Elementary_Functions. |
Most of the constants and functions used in this task are defined in the pre-defined Ada package Ada.Numerics.Elementary_Functions. |
||
<ada> |
<lang ada> |
||
Ada.Numerics.e -- Euler's number |
Ada.Numerics.e -- Euler's number |
||
Ada.Numerics.pi -- pi |
Ada.Numerics.pi -- pi |
||
Line 24: | Line 24: | ||
S'ceiling(x) -- Produces the ceiling 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 |
x**y -- x raised to the y power |
||
</ |
</lang> |
||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
<pre> |
<pre> |
||
Line 49: | Line 49: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
{{works with|QuickBasic|4.5}} |
{{works with|QuickBasic|4.5}} |
||
<qbasic>abs(x) 'absolute value |
<lang qbasic>abs(x) 'absolute value |
||
sqr(x) 'square root |
sqr(x) 'square root |
||
exp(x) 'exponential |
exp(x) 'exponential |
||
log(x) 'natural logarithm |
log(x) 'natural logarithm |
||
x ^ y 'power |
x ^ y 'power |
||
'floor, ceiling, e, and pi not available</ |
'floor, ceiling, e, and pi not available</lang> |
||
=={{header|C}}== |
=={{header|C}}== |
||
Most of the following functions take a double. |
Most of the following functions take a double. |
||
<c>#include <math.h> |
<lang c>#include <math.h> |
||
M_E; /* e - not standard but offered by most implementations */ |
M_E; /* e - not standard but offered by most implementations */ |
||
Line 69: | Line 69: | ||
floor(x); /* floor */ |
floor(x); /* floor */ |
||
ceil(x); /* ceiling */ |
ceil(x); /* ceiling */ |
||
pow(x,y); /* power */</ |
pow(x,y); /* power */</lang> |
||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
<lisp>pi ;pi constant |
<lang lisp>pi ;pi constant |
||
(sqrt x) ;square root |
(sqrt x) ;square root |
||
(log x) ;natural logarithm |
(log x) ;natural logarithm |
||
Line 80: | Line 80: | ||
(floor x) ;floor |
(floor x) ;floor |
||
(ceiling x) ;ceiling |
(ceiling x) ;ceiling |
||
(expt x y) ;power</ |
(expt x y) ;power</lang> |
||
=={{header|D}}== |
=={{header|D}}== |
||
<d>import std.math ; // need to import this module |
<lang d>import std.math ; // need to import this module |
||
E // Euler's number |
E // Euler's number |
||
PI // pi constant |
PI // pi constant |
||
Line 94: | Line 94: | ||
floor(x) // floor |
floor(x) // floor |
||
ceil(x) // ceiling |
ceil(x) // ceiling |
||
pow(x,y) // power</ |
pow(x,y) // power</lang> |
||
=={{header|E}}== |
=={{header|E}}== |
||
Line 182: | Line 182: | ||
=={{header|Java}}== |
=={{header|Java}}== |
||
All of these functions are in Java's <tt>Math</tt> class which, does not require any imports: |
All of these functions are in Java's <tt>Math</tt> class which, does not require any imports: |
||
<java>Math.E; //e |
<lang java>Math.E; //e |
||
Math.PI; //pi |
Math.PI; //pi |
||
Math.sqrt(x); //square root--cube root also available (cbrt) |
Math.sqrt(x); //square root--cube root also available (cbrt) |
||
Line 190: | Line 190: | ||
Math.floor(x); //floor |
Math.floor(x); //floor |
||
Math.ceil(x); //ceiling |
Math.ceil(x); //ceiling |
||
Math.pow(x,y); //power</ |
Math.pow(x,y); //power</lang> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
Line 243: | Line 243: | ||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
Unless otherwise noted, the following functions are for floats only: |
Unless otherwise noted, the following functions are for floats only: |
||
<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 *) |
||
Line 250: | Line 250: | ||
floor x;; (* floor *) |
floor x;; (* floor *) |
||
ceil x;; (* ceiling *) |
ceil x;; (* ceiling *) |
||
x ** y; (* power *)</ |
x ** y; (* power *)</lang> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
<perl>use POSIX; |
<lang perl>use POSIX; |
||
exp(1); # e |
exp(1); # e |
||
Line 263: | Line 263: | ||
POSIX::floor($x); # floor |
POSIX::floor($x); # floor |
||
POSIX::ceil($x); # ceiling |
POSIX::ceil($x); # ceiling |
||
$x**$y; # power</ |
$x**$y; # power</lang> |
||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
<php>M_E; //e |
<lang php>M_E; //e |
||
M_PI; //pi |
M_PI; //pi |
||
sqrt(x); //square root |
sqrt(x); //square root |
||
Line 274: | Line 274: | ||
floor(x); //floor |
floor(x); //floor |
||
ceil(x); //ceiling |
ceil(x); //ceiling |
||
pow(x,y); //power</ |
pow(x,y); //power</lang> |
||
=={{header|Pop11}}== |
=={{header|Pop11}}== |
||
Line 306: | Line 306: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
<python>import math |
<lang python>import math |
||
math.e # e |
math.e # e |
||
Line 318: | Line 318: | ||
math.ceil(x) # ceiling |
math.ceil(x) # ceiling |
||
x ** y # exponentiation (and used with an exponent of 0.5 for square roots) |
x ** y # exponentiation (and used with an exponent of 0.5 for square roots) |
||
</ |
</lang> |
||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
<ruby>Math::E #e |
<lang ruby>Math::E #e |
||
Math::PI #pi |
Math::PI #pi |
||
Math.sqrt(x) #square root |
Math.sqrt(x) #square root |
||
Line 330: | Line 330: | ||
x.floor #floor |
x.floor #floor |
||
x.ceil #ceiling |
x.ceil #ceiling |
||
x ** y #power</ |
x ** y #power</lang> |
||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
<scheme>(sqrt x) ;square root |
<lang scheme>(sqrt x) ;square root |
||
(log x) ;natural logarithm |
(log x) ;natural logarithm |
||
(exp x) ;exponential |
(exp x) ;exponential |
||
Line 339: | Line 339: | ||
(floor x) ;floor |
(floor x) ;floor |
||
(ceiling x) ;ceiling |
(ceiling x) ;ceiling |
||
(expt x y) ;power</ |
(expt x y) ;power</lang> |