Real constants and functions: Difference between revisions

From Rosetta Code
Content added Content deleted
(New page: {{task}}Show how to use the following math constants and functions in your language (if not available, note it): *e (Euler's number) *pi *square root *logarithm (any base allowed) *exponen...)
 
(Added power)
Line 8: Line 8:
*floor (largest integer less than this number--not the same as truncate or int)
*floor (largest integer less than this number--not the same as truncate or int)
*ceiling (smallest integer greater than this number--not the same as round up)
*ceiling (smallest integer greater than this number--not the same as round up)
*power (x<sup>y</sup>)


=={{header|BASIC}}==
=={{header|BASIC}}==
Line 15: Line 16:
exp(x) 'exponential
exp(x) 'exponential
log(x) 'natural logarithm
log(x) 'natural logarithm
x ^ y 'power
'floor, ceiling, e, and pi not available</qbasic>
'floor, ceiling, e, and pi not available</qbasic>


Line 26: Line 28:
Math.abs(x); //absolute value
Math.abs(x); //absolute value
Math.floor(x); //floor
Math.floor(x); //floor
Math.ceil(x); //ceiling</java>
Math.ceil(x); //ceiling
Math.pow(x,y) //power</java>

Revision as of 00:50, 7 May 2008

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):

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

BASIC

Works with: QuickBasic version 4.5

<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</qbasic>

Java

All of these functions are in Java's Math class which, does not require any imports: <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</java>