Published Mar 8, 2024
Contribute to Docs

Dart has a core library dart:math which provides common math methods covering random number generation, trigonometry, and use of mathematical constants such as e and pi.

Note: To use the following methods, import the dart:math library.

import 'dart:math';


Use mathematical constants, such as pi and e.

import 'dart:math';
void main() {

The above code gives the following output:



Perform trigonometric calculations and return the larger or smaller of two numbers using max() and min() methods.

Function Description
max(a, b) Returns the larger of two numbers
min(a, b) Returns the smaller of two numbers
pow(a, b) Returns a to the power of b
log(a) Returns the natural logarithm of a
sqrt(a) Returns the square root of a
sin(a) Returns sine value of a radians
cos(a) Returns cosine value of a radians
tan(a) Returns tangent value of a radians

All contributors

Looking to contribute?

Learn Dart on Codecademy