Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
logarithm
communitycreator

What is log() in Dart?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The log() function in Dart calculates the natural logarithm of a number. The image below shows the mathematical representation of the log() function.

The dart:math module is required for this function.

Syntax

double log(double num)

Parameters

This function requires:

  • A numbermust be greater than 0 for which the logarithm is to be calculated.

Return value

log() returns the natural logarithm of the number sent as a parameter.

  • If the parameter value is less than zero, then log() returns NaN.
  • If the parameter value is zero, then log() returns negativeinfinity.

Code

The following code shows how to use log() in Dart.

import 'dart:convert';
import 'dart:math';
void main() {
//positive number
print("The value of log(10) = ${log(10)}");
// e
print("The value of log(e) = ${log(e)}");
//negative number
print("The value of log(-2) = ${log(-2)}");
//zero number
print("The value of log(0) = ${log(0)}");
}

RELATED TAGS

dart
logarithm
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring