Real constants and functions: Difference between revisions
Content added Content deleted
m (→{{header|True BASIC}}: {{works with|Decimal BASIC}}) |
m (Dialects of BASIC moved to the BASIC section.) |
||
Line 415: | Line 415: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
==={{header|QBasic}}=== |
|||
{{works with|QBasic|1.1}} |
|||
{{works with|QuickBasic|4.5}} |
|||
<syntaxhighlight lang="qbasic">'ceiling and floor easily implemented as functions. |
|||
'e & pi not available- calculate as shown. |
|||
FUNCTION ceiling (x) |
|||
IF x < 0 THEN ceiling = INT(x) ELSE ceiling = INT(x) + 1 |
|||
END FUNCTION |
|||
FUNCTION floor (x) |
|||
IF x > 0 THEN |
|||
floor = INT(x) |
|||
ELSE |
|||
IF x <> INT(x) THEN floor = INT(x) - 1 ELSE floor = INT(x) |
|||
END IF |
|||
END FUNCTION |
|||
PRINT "e = "; EXP(1) ' e not available |
|||
PRINT "PI = "; 4 * ATN(1) ' pi not available |
|||
x = 12.345: y = 1.23 |
|||
PRINT "sqrt = "; SQR(x), x ^ .5 ' square root- NB the unusual name |
|||
PRINT "ln = "; LOG(x) ' natural logarithm base e |
|||
PRINT "log10 = "; LOG(x) / 2.303 ' base 10 logarithm |
|||
PRINT "log = "; LOG(x) / LOG(y) ' arbitrary base logarithm |
|||
PRINT "exp = "; EXP(x) ' exponential |
|||
PRINT "abs = "; ABS(-x) ' absolute value |
|||
PRINT "floor = "; floor(x) ' floor |
|||
PRINT "ceil = "; ceiling(x) ' ceiling |
|||
PRINT "power = "; x ^ y ' power |
|||
END</syntaxhighlight> |
|||
==={{header|Applesoft BASIC}}=== |
==={{header|Applesoft BASIC}}=== |
||
{{works with|Chipmunk Basic}} |
{{works with|Chipmunk Basic}} |
||
Line 474: | Line 440: | ||
280 PRINT "power = ";X^Y :REM power |
280 PRINT "power = ";X^Y :REM power |
||
290 END</syntaxhighlight> |
290 END</syntaxhighlight> |
||
==={{header|BASIC256}}=== |
|||
<syntaxhighlight lang="basic256">e = exp(1) # e not available |
|||
print "e = "; e |
|||
print "PI = "; PI |
|||
x = 12.345 |
|||
y = 1.23 |
|||
print "sqrt = "; sqr(x) # square root |
|||
print "ln = "; log(e) # natural logarithm base e |
|||
print "log10 = "; log10(e) # base 10 logarithm |
|||
print "log = "; log(x)/log(y) # arbitrary base logarithm |
|||
print "exp = "; exp(e) # exponential |
|||
print "abs = "; abs(-1) # absolute value |
|||
print "floor = "; floor(-e) # floor |
|||
print "ceil = "; ceil(-e) # ceiling |
|||
print "power = "; x ^ y # power</syntaxhighlight> |
|||
{{out}} |
|||
<pre>e = 2.71828182846 |
|||
PI = 3.14159265359 |
|||
sqrt = 3.51354521815 |
|||
ln = 1.0 |
|||
log10 = 0.4342944819 |
|||
log = 12.1404787425 |
|||
exp = 15.1542622415 |
|||
abs = 1 |
|||
floor = -3 |
|||
ceil = -2 |
|||
power = 22.0056421324</pre> |
|||
==={{header|BBC BASIC}}=== |
|||
<syntaxhighlight lang="bbcbasic"> e = EXP(1) |
|||
Pi = PI |
|||
Sqr2 = SQR(2) |
|||
Ln2 = LN(2) |
|||
Log2 = LOG(2) : REM Base 10 |
|||
Exp2 = EXP(2) |
|||
Abs2 = ABS(-2) |
|||
Floor = INT(1.234) |
|||
Ceil = FNceil(1.234) |
|||
Power = 1.23^4 |
|||
END |
|||
DEF FNceil(n) = INT(n) - (INT(n) <> n) |
|||
</syntaxhighlight> |
|||
==={{header|Chipmunk Basic}}=== |
==={{header|Chipmunk Basic}}=== |
||
Line 495: | Line 507: | ||
260 if x < 0 then print int(x) else print int(x)+1 |
260 if x < 0 then print int(x) else print int(x)+1 |
||
270 end sub</syntaxhighlight> |
270 end sub</syntaxhighlight> |
||
==={{header|FreeBASIC}}=== |
|||
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64 |
|||
#Include "crt/math.bi" |
|||
Print M_E '' constant "e" from C runtime library |
|||
Print M_PI '' constant "pi" from C runtime library |
|||
Print Sqr(2) '' square root function built into FB |
|||
Print Log(M_E) '' log to base "e" built into FB |
|||
Print log10(10) '' log to base 10 from C runtime library |
|||
Print Exp(1) '' exponential function built into FB |
|||
Print Abs(-1) '' absolute value function (integers or floats) built into FB |
|||
Print Int(-2.5) '' floor function built into FB |
|||
Print ceil(-2.5) '' ceiling function from C runtime library |
|||
Print 2.5 ^ 3.5 '' exponentiation operator built into FB |
|||
Sleep </syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
2.718281828459045 |
|||
3.141592653589793 |
|||
1.414213562373095 |
|||
1 |
|||
1 |
|||
2.718281828459045 |
|||
1 |
|||
-3 |
|||
-2 |
|||
24.70529422006547 |
|||
</pre> |
|||
==={{header|FutureBasic}}=== |
|||
<syntaxhighlight lang="futurebasic">window 1 |
|||
text ,,,,, 60// set tab width |
|||
print @"exp:", exp(1) |
|||
print @"pi:", pi |
|||
print @"sqr:", sqr(2) |
|||
print @"log:", log(2) |
|||
print @"log2:", log2(2) |
|||
print @"log10", log10(2) |
|||
print @"abs:", abs(-2) |
|||
print @"floor:", int(1.534) |
|||
print @"ceil:", val( using"###"; 1.534 ) |
|||
print @"power:", 1.23 ^ 4 |
|||
HandleEvents</syntaxhighlight> |
|||
Output: |
|||
<pre> |
|||
exp: 2.7182818285 |
|||
pi: 3.1415926536 |
|||
sqr: 1.4142135624 |
|||
log: 0.6931471806 |
|||
log2: 1 |
|||
log10 0.3010299957 |
|||
abs: 2 |
|||
floor: 2 |
|||
ceil: 2 |
|||
power: 2.28886641 |
|||
</pre> |
|||
==={{header|Gambas}}=== |
==={{header|Gambas}}=== |
||
Line 539: | Line 612: | ||
240 PRINT "power = "; X ^Y ' power |
240 PRINT "power = "; X ^Y ' power |
||
250 END</syntaxhighlight> |
250 END</syntaxhighlight> |
||
==={{header|IS-BASIC}}=== |
|||
<syntaxhighlight lang="is-basic">100 LET X=2:LET Y=5 |
|||
110 PRINT EXP(1) ! value of e |
|||
120 PRINT PI ! value of Pi |
|||
130 PRINT ROUND(PI,3) ! rounds Pi to 3 decimal places |
|||
140 PRINT TRUNCATE(PI,3) ! cuts 3 decimal places from Pi |
|||
150 PRINT SQR(X) ! square root of x |
|||
160 PRINT LOG(X) ! the natural logarithm of number x |
|||
170 PRINT LOG2(X) ! logarithm of x to base 2 |
|||
180 PRINT LOG10(X) ! logarithm of x to base 10 |
|||
190 PRINT EXP(X) ! exponential |
|||
200 PRINT ABS(X) ! the absolute value of a number |
|||
210 PRINT INT(X) ! the largest whole number not bigger than x |
|||
220 PRINT IP(X) ! the integer part of x |
|||
230 PRINT FP(X) ! stands for fractorial part |
|||
240 PRINT CEIL(X) ! ceiling: gives the smallest whole number not less than x |
|||
250 PRINT X^Y ! power |
|||
260 PRINT MIN(X,Y) ! the smaller number of x and y |
|||
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</syntaxhighlight> |
|||
==={{header|Liberty BASIC}}=== |
|||
{{works with|Just BASIC}} |
|||
Ceiling and floor easily implemented as functions. |
|||
<br> |
|||
sqr( is the LB function for square root. |
|||
<br> |
|||
e & pi not available- calculate as shown. |
|||
<syntaxhighlight lang="lb"> |
|||
print exp(1) ' e not available |
|||
print 4 *atn(1) ' pi not available |
|||
x =12.345: y =1.23 |
|||
print sqr(x), x^0.5 ' square root- NB the unusual name |
|||
print log(x) ' natural logarithm base e |
|||
print log(x) /2.303 ' base 10 logarithm |
|||
print log(x) / log(y) ' arbitrary base logarithm |
|||
print exp(x) ' exponential |
|||
print abs(x) ' absolute value |
|||
print floor(x) ' floor |
|||
print ceiling(x) ' ceiling |
|||
print x^y ' power |
|||
end |
|||
function floor(x) |
|||
if x >0 then |
|||
floor =int(x) |
|||
else |
|||
if x <>int(x) then floor =int(x) -1 else floor =int(x) |
|||
end if |
|||
end function |
|||
function ceiling(x) |
|||
if x <0 then |
|||
ceiling =int(x) |
|||
else |
|||
ceiling =int(x) +1 |
|||
end if |
|||
end function |
|||
</syntaxhighlight> |
|||
==={{header|MSX Basic}}=== |
==={{header|MSX Basic}}=== |
||
Line 563: | Line 699: | ||
</syntaxhighlight> |
</syntaxhighlight> |
||
==={{header| |
==={{header|PureBasic}}=== |
||
<syntaxhighlight lang="purebasic">Debug #E |
|||
{{works with|Windows XBasic}} |
|||
Debug #PI |
|||
<syntaxhighlight lang="qbasic">PROGRAM "progname" |
|||
Debug Sqr(f) |
|||
VERSION "0.0000" |
|||
Debug Log(f) |
|||
Debug Exp(f) |
|||
Debug Log10(f) |
|||
Debug Abs(f) |
|||
Debug Pow(f,f)</syntaxhighlight> |
|||
==={{header|QBasic}}=== |
|||
IMPORT "xma" |
|||
{{works with|QBasic|1.1}} |
|||
{{works with|QuickBasic|4.5}} |
|||
<syntaxhighlight lang="qbasic">'ceiling and floor easily implemented as functions. |
|||
'e & pi not available- calculate as shown. |
|||
FUNCTION ceiling (x) |
|||
IF x < 0 THEN ceiling = INT(x) ELSE ceiling = INT(x) + 1 |
|||
DECLARE FUNCTION Ceil (x) |
|||
DECLARE FUNCTION Floor (x) |
|||
FUNCTION Entry () |
|||
DOUBLE e, pi, x, y |
|||
e = EXP(1) |
|||
PRINT "e = "; e ' e not available |
|||
pi = 4 * ATAN(1) |
|||
PRINT "pi = "; pi ' pi not available |
|||
x = 12.345 |
|||
y = 1.23 |
|||
PRINT "sqrt = "; SQRT (x) ' square root |
|||
PRINT "ln = "; LOG (x) ' natural logarithm base e |
|||
PRINT "log10 = "; LOG10 (x) ' base 10 logarithm |
|||
PRINT "log = "; LOG (x) / LOG (y) ' arbitrary base logarithm |
|||
PRINT "exp = "; EXP (x) ' exponential |
|||
PRINT "abs = "; ABS (-x) ' absolute value |
|||
PRINT "Floor = "; Floor (x) ' Floor easily implemented as functions |
|||
PRINT "Ceil = "; Ceil (x) ' Ceil easily implemented as functions |
|||
PRINT "power = "; x ** y ' power |
|||
END FUNCTION |
END FUNCTION |
||
FUNCTION |
FUNCTION floor (x) |
||
IF x < 0 THEN RETURN INT(x) ELSE RETURN INT(x) + 1 |
|||
END FUNCTION |
|||
FUNCTION Floor (x) |
|||
IF x > 0 THEN |
IF x > 0 THEN |
||
floor = INT(x) |
|||
ELSE |
ELSE |
||
IF x <> INT(x) THEN floor = INT(x) - 1 ELSE floor = INT(x) |
|||
END IF |
END IF |
||
END FUNCTION |
END FUNCTION |
||
END PROGRAM |
|||
</syntaxhighlight> |
|||
PRINT "e = "; EXP(1) ' e not available |
|||
==={{header|IS-BASIC}}=== |
|||
PRINT "PI = "; 4 * ATN(1) ' pi not available |
|||
<syntaxhighlight lang="is-basic">100 LET X=2:LET Y=5 |
|||
110 PRINT EXP(1) ! value of e |
|||
x = 12.345: y = 1.23 |
|||
120 PRINT PI ! value of Pi |
|||
130 PRINT ROUND(PI,3) ! rounds Pi to 3 decimal places |
|||
PRINT "sqrt = "; SQR(x), x ^ .5 ' square root- NB the unusual name |
|||
140 PRINT TRUNCATE(PI,3) ! cuts 3 decimal places from Pi |
|||
PRINT "ln = "; LOG(x) ' natural logarithm base e |
|||
PRINT "log10 = "; LOG(x) / 2.303 ' base 10 logarithm |
|||
PRINT "log = "; LOG(x) / LOG(y) ' arbitrary base logarithm |
|||
PRINT "exp = "; EXP(x) ' exponential |
|||
PRINT "abs = "; ABS(-x) ' absolute value |
|||
PRINT "floor = "; floor(x) ' floor |
|||
PRINT "ceil = "; ceiling(x) ' ceiling |
|||
PRINT "power = "; x ^ y ' power |
|||
END</syntaxhighlight> |
|||
230 PRINT FP(X) ! stands for fractorial part |
|||
240 PRINT CEIL(X) ! ceiling: gives the smallest whole number not less than x |
|||
==={{header|Run BASIC}}=== |
|||
250 PRINT X^Y ! power |
|||
{{works with|Just BASIC}} |
|||
260 PRINT MIN(X,Y) ! the smaller number of x and y |
|||
<syntaxhighlight lang="runbasic">print "exp:";chr$(9); EXP(1) |
|||
270 PRINT MAX(X,Y) ! the bigger number of x and y |
|||
print "PI:";chr$(9); 4 * ATN(1) |
|||
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 |
|||
print "Sqr2:";chr$(9); SQR(2) |
|||
290 PRINT INF ! The largest positive number the tinterpreter can handle. This number is 9.999999999*10^62</syntaxhighlight> |
|||
print "Log2:";chr$(9); LOG(2) : REM Base 10 |
|||
print "Exp2:";chr$(9); EXP(2) |
|||
print "Abs2:";chr$(9); ABS(-2) |
|||
print "Floor:";chr$(9); INT(1.534) |
|||
print "ceil:";chr$(9); val(using("###",1.534)) |
|||
print "Power:";chr$(9); 1.23^4</syntaxhighlight> |
|||
<pre>exp: 2.71828183 |
|||
PI: 3.14285707 |
|||
Sqr2: 1.41421356 |
|||
Log2: 0.693147181 |
|||
Exp2: 7.3890561 |
|||
Abs2: 2 |
|||
Floor: 1 |
|||
ceil: 2 |
|||
Power: 2.28886641</pre> |
|||
==={{header|Sinclair ZX81 BASIC}}=== |
==={{header|Sinclair ZX81 BASIC}}=== |
||
Line 664: | Line 796: | ||
NB. Both <math>x</math> and <math>y</math> can be real numbers. |
NB. Both <math>x</math> and <math>y</math> can be real numbers. |
||
==={{header| |
==={{header|TI-89 BASIC}}=== |
||
{| |
|||
<syntaxhighlight lang="bbcbasic"> e = EXP(1) |
|||
|- |
|||
Pi = PI |
|||
! Mathematical !! TI-89 !! Notes |
|||
Sqr2 = SQR(2) |
|||
|- |
|||
Ln2 = LN(2) |
|||
| <math>e </math> || <code style="font-family:'TI Uni'">ℯ </code> || (U+212F SCRIPT SMALL E) |
|||
Log2 = LOG(2) : REM Base 10 |
|||
|- |
|||
Exp2 = EXP(2) |
|||
| <math>\pi </math> || <code style="font-family:'TI Uni'">π </code> || (U+03C0 GREEK SMALL LETTER PI) |
|||
Abs2 = ABS(-2) |
|||
|- |
|||
Floor = INT(1.234) |
|||
| <math>\sqrt{x} </math> || <code style="font-family:'TI Uni'">√(x) </code> || (U+221A SQUARE ROOT) |
|||
Ceil = FNceil(1.234) |
|||
|- |
|||
Power = 1.23^4 |
|||
| <math>\log_e(x) </math> || <code style="font-family:'TI Uni'">ln(x) </code> |
|||
END |
|||
|- |
|||
| <math>\log_{10}(x) </math> || <code style="font-family:'TI Uni'">log(x) </code> |
|||
DEF FNceil(n) = INT(n) - (INT(n) <> n) |
|||
|- |
|||
</syntaxhighlight> |
|||
| <math>\log_b(x) </math> || <code style="font-family:'TI Uni'">log(b, x) </code> || The optional base argument comes ''first'' |
|||
|- |
|||
| <math>\lfloor x\rfloor</math> || <code style="font-family:'TI Uni'">floor(x) </code> |
|||
|- |
|||
| <math>\lceil x\rceil </math> || <code style="font-family:'TI Uni'">ceiling(x)</code> |
|||
|- |
|||
| <math>x^y </math> || <code style="font-family:'TI Uni'">x^y </code> |
|||
|} |
|||
==={{header|True BASIC}}=== |
|||
{{works with|Decimal BASIC}} |
|||
<syntaxhighlight lang="qbasic">FUNCTION floor(x) |
|||
IF x > 0 THEN |
|||
LET floor = INT(x) |
|||
ELSE |
|||
IF x <> INT(x) THEN LET floor = INT(x) - 1 ELSE LET floor = INT(x) |
|||
END IF |
|||
END FUNCTION |
|||
PRINT "e = "; exp(1) ! e not available |
|||
=={{header|BASIC256}}== |
|||
PRINT "PI = "; PI |
|||
<syntaxhighlight lang="basic256">e = exp(1) # e not available |
|||
print "e = "; e |
|||
print "PI = "; PI |
|||
LET x = 12.345 |
|||
LET y = 1.23 |
|||
PRINT "sqrt = "; SQR(x), x^0.5 ! square root- NB the unusual name |
|||
PRINT "ln = "; LOG(x) ! natural logarithm base e |
|||
PRINT "log2 = "; LOG2(x) ! base 2 logarithm |
|||
PRINT "log10 = "; LOG10(x) ! base 10 logarithm |
|||
PRINT "log = "; LOG(x)/LOG(y) ! arbitrary base logarithm |
|||
PRINT "exp = "; EXP(x) ! exponential |
|||
PRINT "abs = "; ABS(-1) ! absolute value |
|||
PRINT "floor = "; floor(x) ! floor easily implemented as functions |
|||
PRINT "ceil = "; CEIL(x) ! ceiling |
|||
PRINT "power = "; x ^ y ! power |
|||
END</syntaxhighlight> |
|||
==={{header|XBasic}}=== |
|||
{{works with|Windows XBasic}} |
|||
<syntaxhighlight lang="qbasic">PROGRAM "realcaf" |
|||
VERSION "0.0000" |
|||
IMPORT "xma" |
|||
DECLARE FUNCTION Entry () |
|||
DECLARE FUNCTION Ceil (x) |
|||
DECLARE FUNCTION Floor (x) |
|||
FUNCTION Entry () |
|||
DOUBLE e, pi, x, y |
|||
e = EXP(1) |
|||
PRINT "e = "; e ' e not available |
|||
pi = 4 * ATAN(1) |
|||
PRINT "pi = "; pi ' pi not available |
|||
x = 12.345 |
|||
y = 1.23 |
|||
PRINT "sqrt = "; SQRT (x) ' square root |
|||
PRINT "ln = "; LOG (x) ' natural logarithm base e |
|||
PRINT "log10 = "; LOG10 (x) ' base 10 logarithm |
|||
PRINT "log = "; LOG (x) / LOG (y) ' arbitrary base logarithm |
|||
PRINT "exp = "; EXP (x) ' exponential |
|||
PRINT "abs = "; ABS (-x) ' absolute value |
|||
PRINT "Floor = "; Floor (x) ' Floor easily implemented as functions |
|||
PRINT "Ceil = "; Ceil (x) ' Ceil easily implemented as functions |
|||
PRINT "power = "; x ** y ' power |
|||
END FUNCTION |
|||
FUNCTION Ceil (x) |
|||
IF x < 0 THEN RETURN INT(x) ELSE RETURN INT(x) + 1 |
|||
END FUNCTION |
|||
FUNCTION Floor (x) |
|||
IF x > 0 THEN |
|||
RETURN INT(x) |
|||
ELSE |
|||
IF x <> INT(x) THEN RETURN INT(x) - 1 ELSE RETURN INT(x) |
|||
END IF |
|||
END FUNCTION |
|||
END PROGRAM |
|||
</syntaxhighlight> |
|||
==={{header|Yabasic}}=== |
|||
<syntaxhighlight lang="yabasic">print "e = ", euler |
|||
print "pi = ", pi |
|||
x = 12.345 |
x = 12.345 |
||
y = 1.23 |
y = 1.23 |
||
print "sqrt = " |
print "sqrt = ", sqrt(2) // square root |
||
print "ln = " |
print "ln = ", log(euler) // natural logarithm base e |
||
print " |
print "log = ", log(x, y) // arbitrary base y logarithm |
||
print " |
print "exp = ", exp(euler) // exponential |
||
print " |
print "abs = ", abs(-1) // absolute value |
||
print " |
print "floor = ", floor(-euler) // floor |
||
print " |
print "ceil = ", ceil(-euler) // ceiling |
||
print " |
print "power = ", x ^ y, " ", x ** y // power |
||
end</syntaxhighlight> |
|||
{{out}} |
{{out}} |
||
<pre>e = 2. |
<pre>e = 2.71828 |
||
pi = 3.14159 |
|||
sqrt = |
sqrt = 1.41421 |
||
ln = 1 |
ln = 1 |
||
log = 12.1405 |
|||
log10 = 0.4342944819 |
|||
exp = 15.1543 |
|||
exp = 15.1542622415 |
|||
abs = 1 |
abs = 1 |
||
floor = -3 |
floor = -3 |
||
ceil = -2 |
ceil = -2 |
||
power = 22. |
power = 22.0056 22.0056</pre> |
||
=={{header|bc}}== |
=={{header|bc}}== |
||
Line 1,353: | Line 1,564: | ||
The 4 need not be named as 4.0, or 4D0, as 4 the integer will be converted by the compiler to double precision, because it is to meet a known double precision value in simple multiplication and so will be promoted. Hopefully, at compile time. |
The 4 need not be named as 4.0, or 4D0, as 4 the integer will be converted by the compiler to double precision, because it is to meet a known double precision value in simple multiplication and so will be promoted. Hopefully, at compile time. |
||
=={{header|FreeBASIC}}== |
|||
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win64 |
|||
#Include "crt/math.bi" |
|||
Print M_E '' constant "e" from C runtime library |
|||
Print M_PI '' constant "pi" from C runtime library |
|||
Print Sqr(2) '' square root function built into FB |
|||
Print Log(M_E) '' log to base "e" built into FB |
|||
Print log10(10) '' log to base 10 from C runtime library |
|||
Print Exp(1) '' exponential function built into FB |
|||
Print Abs(-1) '' absolute value function (integers or floats) built into FB |
|||
Print Int(-2.5) '' floor function built into FB |
|||
Print ceil(-2.5) '' ceiling function from C runtime library |
|||
Print 2.5 ^ 3.5 '' exponentiation operator built into FB |
|||
Sleep </syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
2.718281828459045 |
|||
3.141592653589793 |
|||
1.414213562373095 |
|||
1 |
|||
1 |
|||
2.718281828459045 |
|||
1 |
|||
-3 |
|||
-2 |
|||
24.70529422006547 |
|||
</pre> |
|||
=={{header|Free Pascal}}== |
=={{header|Free Pascal}}== |
||
Line 1,402: | Line 1,582: | ||
x^y |
x^y |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|FutureBasic}}== |
|||
<syntaxhighlight lang="futurebasic">window 1 |
|||
text ,,,,, 60// set tab width |
|||
print @"exp:", exp(1) |
|||
print @"pi:", pi |
|||
print @"sqr:", sqr(2) |
|||
print @"log:", log(2) |
|||
print @"log2:", log2(2) |
|||
print @"log10", log10(2) |
|||
print @"abs:", abs(-2) |
|||
print @"floor:", int(1.534) |
|||
print @"ceil:", val( using"###"; 1.534 ) |
|||
print @"power:", 1.23 ^ 4 |
|||
HandleEvents</syntaxhighlight> |
|||
Output: |
|||
<pre> |
|||
exp: 2.7182818285 |
|||
pi: 3.1415926536 |
|||
sqr: 1.4142135624 |
|||
log: 0.6931471806 |
|||
log2: 1 |
|||
log10 0.3010299957 |
|||
abs: 2 |
|||
floor: 2 |
|||
ceil: 2 |
|||
power: 2.28886641 |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
Line 1,796: | Line 1,945: | ||
1.64->ceil |
1.64->ceil |
||
1.64->pow(10.0)</syntaxhighlight> |
1.64->pow(10.0)</syntaxhighlight> |
||
=={{header|Liberty BASIC}}== |
|||
Ceiling and floor easily implemented as functions. |
|||
<br> |
|||
sqr( is the LB function for square root. |
|||
<br> |
|||
e & pi not available- calculate as shown. |
|||
<syntaxhighlight lang="lb"> |
|||
print exp( 1) ' e not available |
|||
print 4 *atn( 1) ' pi not available |
|||
x =12.345: y =1.23 |
|||
print sqr( x), x^0.5 ' square root- NB the unusual name |
|||
print log( x) ' natural logarithm base e |
|||
print log( x) /2.303 ' base 10 logarithm |
|||
print log( x) /log( y) ' arbitrary base logarithm |
|||
print exp( x) ' exponential |
|||
print abs( x) ' absolute value |
|||
print floor( x) ' floor |
|||
print ceiling( x) ' ceiling |
|||
print x^y ' power |
|||
end |
|||
function floor( x) |
|||
if x >0 then |
|||
floor =int( x) |
|||
else |
|||
if x <>int( x) then floor =int( x) -1 else floor =int( x) |
|||
end if |
|||
end function |
|||
function ceiling( x) |
|||
if x <0 then |
|||
ceiling =int( x) |
|||
else |
|||
ceiling =int( x) +1 |
|||
end if |
|||
end function |
|||
</syntaxhighlight> |
|||
=={{header|Lingo}}== |
=={{header|Lingo}}== |
||
Line 2,716: | Line 2,824: | ||
Write-Host ([Math]::Ceiling(3.14)) |
Write-Host ([Math]::Ceiling(3.14)) |
||
Write-Host ([Math]::Pow(2, 3))</syntaxhighlight> |
Write-Host ([Math]::Pow(2, 3))</syntaxhighlight> |
||
=={{header|PureBasic}}== |
|||
<syntaxhighlight 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)</syntaxhighlight> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
||
Line 3,088: | Line 3,186: | ||
exp(x) #exponential |
exp(x) #exponential |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
=={{header|Run BASIC}}== |
|||
<syntaxhighlight lang="runbasic">print "exp:";chr$(9); EXP(1) |
|||
print "PI:";chr$(9); 22/7 |
|||
print "Sqr2:";chr$(9); SQR(2) |
|||
print "Log2:";chr$(9); LOG(2) : REM Base 10 |
|||
print "Exp2:";chr$(9); EXP(2) |
|||
print "Abs2:";chr$(9); ABS(-2) |
|||
print "Floor:";chr$(9); INT(1.534) |
|||
print "ceil:";chr$(9); val(using("###",1.534)) |
|||
print "Power:";chr$(9); 1.23^4</syntaxhighlight> |
|||
<pre>exp: 2.71828183 |
|||
PI: 3.14285707 |
|||
Sqr2: 1.41421356 |
|||
Log2: 0.693147181 |
|||
Exp2: 7.3890561 |
|||
Abs2: 2 |
|||
Floor: 1 |
|||
ceil: 2 |
|||
Power: 2.28886641</pre> |
|||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
Line 3,310: | Line 3,388: | ||
math::constants::constants e pi |
math::constants::constants e pi |
||
puts "e = $e, pi = $pi"</syntaxhighlight> |
puts "e = $e, pi = $pi"</syntaxhighlight> |
||
=={{header|TI-89 BASIC}}== |
|||
{| |
|||
|- |
|||
! Mathematical !! TI-89 !! Notes |
|||
|- |
|||
| <math>e </math> || <code style="font-family:'TI Uni'">ℯ </code> || (U+212F SCRIPT SMALL E) |
|||
|- |
|||
| <math>\pi </math> || <code style="font-family:'TI Uni'">π </code> || (U+03C0 GREEK SMALL LETTER PI) |
|||
|- |
|||
| <math>\sqrt{x} </math> || <code style="font-family:'TI Uni'">√(x) </code> || (U+221A SQUARE ROOT) |
|||
|- |
|||
| <math>\log_e(x) </math> || <code style="font-family:'TI Uni'">ln(x) </code> |
|||
|- |
|||
| <math>\log_{10}(x) </math> || <code style="font-family:'TI Uni'">log(x) </code> |
|||
|- |
|||
| <math>\log_b(x) </math> || <code style="font-family:'TI Uni'">log(b, x) </code> || The optional base argument comes ''first'' |
|||
|- |
|||
| <math>\lfloor x\rfloor</math> || <code style="font-family:'TI Uni'">floor(x) </code> |
|||
|- |
|||
| <math>\lceil x\rceil </math> || <code style="font-family:'TI Uni'">ceiling(x)</code> |
|||
|- |
|||
| <math>x^y </math> || <code style="font-family:'TI Uni'">x^y </code> |
|||
|} |
|||
=={{header|True BASIC}}== |
|||
{{works with|Decimal BASIC}} |
|||
<syntaxhighlight lang="qbasic">FUNCTION floor(x) |
|||
IF x > 0 THEN |
|||
LET floor = INT(x) |
|||
ELSE |
|||
IF x <> INT(x) THEN LET floor = INT(x) - 1 ELSE LET floor = INT(x) |
|||
END IF |
|||
END FUNCTION |
|||
PRINT "e = "; exp(1) ! e not available |
|||
PRINT "PI = "; PI |
|||
LET x = 12.345 |
|||
LET y = 1.23 |
|||
PRINT "sqrt = "; SQR(x), x^0.5 ! square root- NB the unusual name |
|||
PRINT "ln = "; LOG(x) ! natural logarithm base e |
|||
PRINT "log2 = "; LOG2(x) ! base 2 logarithm |
|||
PRINT "log10 = "; LOG10(x) ! base 10 logarithm |
|||
PRINT "log = "; LOG(x)/LOG(y) ! arbitrary base logarithm |
|||
PRINT "exp = "; EXP(x) ! exponential |
|||
PRINT "abs = "; ABS(-1) ! absolute value |
|||
PRINT "floor = "; floor(x) ! floor easily implemented as functions |
|||
PRINT "ceil = "; CEIL(x) ! ceiling |
|||
PRINT "power = "; x ^ y ! power |
|||
END</syntaxhighlight> |
|||
=={{header|UNIX Shell}}== |
=={{header|UNIX Shell}}== |
||
Line 3,486: | Line 3,512: | ||
4.0000000000000000 |
4.0000000000000000 |
||
</pre> |
</pre> |
||
=={{header|Yabasic}}== |
|||
<syntaxhighlight lang="yabasic">print "e = ", euler |
|||
print "pi = ", pi |
|||
x = 12.345 |
|||
y = 1.23 |
|||
print "sqrt = ", sqrt(2) // square root |
|||
print "ln = ", log(euler) // natural logarithm base e |
|||
print "log = ", log(x, y) // arbitrary base y logarithm |
|||
print "exp = ", exp(euler) // exponential |
|||
print "abs = ", abs(-1) // absolute value |
|||
print "floor = ", floor(-euler) // floor |
|||
print "ceil = ", ceil(-euler) // ceiling |
|||
print "power = ", x ^ y, " ", x ** y // power |
|||
end</syntaxhighlight> |
|||
{{out}} |
|||
<pre>e = 2.71828 |
|||
pi = 3.14159 |
|||
sqrt = 1.41421 |
|||
ln = 1 |
|||
log = 12.1405 |
|||
exp = 15.1543 |
|||
abs = 1 |
|||
floor = -3 |
|||
ceil = -2 |
|||
power = 22.0056 22.0056</pre> |
|||
=={{header|Zig}}== |
=={{header|Zig}}== |