TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C# Math.Log and Log10 Methods

This C# example program shows the Math.Log and Math.Log10 methods from the .NET Framework.

Math.Log, Log10. The Math class provides logarithms.

With the Math.Log and Math.Log10 methods in the System namespace, we compute logarithms with a specific base or base 10. These methods are tested—they do not need to be debugged.

Example. Here we compute the logarithms of some known numbers. The logarithm of 1 with base "e" is always zero—the method matches this result. The logarithm of 1000 with base 10 is always 3. This is because 10 to the power of 3 is 1000.

Finally: You can duplicate the effects of Log10 with Log by passing 10 as the second argument.

C# program that uses Log and Log10 methods

using System;

class Program
{
    static void Main()
    {
	double a = Math.Log(1);
	Console.WriteLine(a);

	double b = Math.Log10(1000);
	Console.WriteLine(b);

	double c = Math.Log(1000, 10);
	Console.WriteLine(c);
    }
}

Output

0
3
3

Uses. What are some uses for Math.Log and Math.Log10? Generally, these methods are used for scientific formulas. Developing a fractal generator in the C# language would be interesting, and it would involve logarithms.

Logarithm: Wikipedia

Summary. The Math.Log and Math.Log10 methods provide accurate results for logarithms in the C# language. They are built into the Framework. This means they don't require many additional development resources.

Tip: If you need to optimize their performance, try using a lookup table to cache or precompute the most common values.


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf