Skip to content
This repository was archived by the owner on Feb 27, 2026. It is now read-only.

Commit 8d21ec3

Browse files
authored
[Term Entry] C# Math-functions: Log10()
* Add log10.md file * EDIT: Add log10.md with minor corrections * minor content fixes * Update log10.md * Update log10.md ---------
1 parent a57d584 commit 8d21ec3

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

  • content/c-sharp/concepts/math-functions/terms/log10
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
---
2+
Title: 'Log10()'
3+
Description: 'Returns the base-10 logarithm of a specified number.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Web Development'
7+
Tags:
8+
- 'Arithmetic'
9+
- 'Functions'
10+
- 'Math'
11+
- 'Methods'
12+
CatalogContent:
13+
- 'learn-c-sharp'
14+
- 'paths/computer-science'
15+
---
16+
17+
In C#, the **`Math.Log10()`** [method](https://www.codecademy.com/resources/docs/c-sharp/methods) calculates the base-10 logarithm of a given number. This logarithm represents the power to which 10 must be raised to obtain the input value. The method is defined in the `System` namespace.
18+
19+
## Syntax
20+
21+
```pseudo
22+
Math.Log10(number);
23+
```
24+
25+
**Parameters:**
26+
27+
- `number`: A `double` value whose base-10 logarithm is computed.
28+
29+
**Return value:**
30+
31+
Returns a `double` that represents the base-10 logarithm of `number`.
32+
33+
Return values for different inputs:
34+
35+
- If the input is a positive number, the method returns its base-10 logarithm.
36+
- If the input is `0`, the method returns `NegativeInfinity`.
37+
- If the input is a negative number, the method returns `NaN`.
38+
- If the input is `NaN`, the method returns `NaN`.
39+
- If the input is `PositiveInfinity`, the method returns `PositiveInfinity`.
40+
- If the input is `NegativeInfinity`, the method returns `NaN`.
41+
42+
## Example
43+
44+
The example below demonstrates the return values of `Math.Log10()` for different inputs:
45+
46+
```cs
47+
using System;
48+
49+
class Geeks {
50+
public static void Main(String[] args) {
51+
double a = 4.55;
52+
double b = 0;
53+
double c = -2.45;
54+
double nan = Double.NaN;
55+
double positiveInfinity = Double.PositiveInfinity;
56+
double negativeInfinity = Double.NegativeInfinity;
57+
58+
Console.WriteLine(Math.Log10(a));
59+
Console.WriteLine(Math.Log10(b));
60+
Console.WriteLine(Math.Log10(c));
61+
Console.WriteLine(Math.Log10(nan));
62+
Console.WriteLine(Math.Log10(positiveInfinity));
63+
Console.WriteLine(Math.Log10(negativeInfinity));
64+
}
65+
}
66+
```
67+
68+
The output of the code is:
69+
70+
```shell
71+
0.658011396657112
72+
-Infinity
73+
NaN
74+
NaN
75+
Infinity
76+
NaN
77+
```
78+
79+
## Codebyte Example
80+
81+
This codebyte example calculates the base-10 logarithm of a given number and prints the result:
82+
83+
```codebyte/csharp
84+
using System;
85+
86+
class Program {
87+
static void Main() {
88+
double x = 10.0;
89+
double result = Math.Log10(x);
90+
91+
Console.WriteLine($"The base-10 logarithm of {x} is {result}");
92+
}
93+
}
94+
```

0 commit comments

Comments
 (0)