4. Explain .ceil() and .cbrt() functions with example
Answers
Answered by
5
Question:-
- Explain Math.ceil() and Math.cbrt() functions with example
Answer:-
•Math.ceil():-
- Rounds up the value upto next higher integer
- It always returns the value in double data type
- Example:- Math.ceil(2.5) Here in this example, the value gets rounded up to next higher integer i.e. 3 but the output will be 3.0 because it returns in double data type value
- Let's have another example to understand the concept of ceil().... Math.ceil(4.3) Here in this example, the value gets rounded up to next higher integer i.e. 5 but the output will be 5.0 because it returns in double data type.
- In case of negative numbers, Math.ceil(-4.3) here it will return -4.0 as -4.0 is higher than -4.3.
•Math.cbrt():-
- Finds the cube root of a number
- Like Math.ceil(), Math.cbrt() also returns double data type value
- A very simple example for this is Math.cbrt(8) here it will return 2 in double data type value i.e. the output will be 2.0
- Another example is Math.cbrt(-64) Here cube root of 64 is 4, but 64 is negative so the correct output will be -4 in double data type value i.e. -4.0
More about Math Functions:-
- Math.max() is used to find the maximum value between 2 numbers. SYNTAX:- Math.max(a,b);
- Math.min() returns the minimum value between two numbers. SYNTAX:- Math.min(x,y);
- Math.abs() returns absolute value of the given number. SYNTAX:- Math.abs(a);
- Math.ceil() returns rounded value upto nearest higher integer. SYNTAX:- Math.ceil(x);
- Math.floor() returns rounded value upto nearest lower integer. SYNTAX;- Math.floor(x);
- Math.round() returns the rounded value of the number upto nearest integer. SYNTAX:- Math.round(x);
- Math.cbrt() returns cube root of a number. SYNTAX:- Math.cbrt(x);
- Math.sqrt() returns square root of a positive real number. SYNTAX:- Math.sqrt(x);
Similar questions