C#

double

System

using System;
*//*
*// Compute the squares of the first parameters to Math.Pow.*
*//*
double value1 = Math.Pow(2, 2);
double value2 = Math.Pow(3, 2);
double value3 = Math.Pow(4, 2);
double value4 = Math.Pow(5, 2);
*//*
*// Compute the cubes of these values.*
*//*
double value5 = Math.Pow(2, 3);
double value6 = Math.Pow(3, 3);
double value7 = Math.Pow(4, 3);
double value8 = Math.Pow(5, 3);
*//*
*// Check some edge cases with the smallest, biggest,*
*// ... and special values.*
*//*
double value9 = Math.Pow(double.MinValue, double.MaxValue);
double value10 = Math.Pow(double.MinValue, 0);
double value11 = Math.Pow(double.NaN, 2);
double value12 = Math.Pow(double.PositiveInfinity, 2);
double value13 = Math.Pow(double.NegativeInfinity, 2);
*//*
*// Compute fractional powers.*
*//*
double value14 = Math.Pow(2, 2.1);
double value15 = Math.Pow(Math.E, 2);
double value16 = Math.Pow(Math.PI, 1);
*//*
*// Write results to the screen.*
*//*
Console.WriteLine(value1);
Console.WriteLine(value2);
Console.WriteLine(value3);
Console.WriteLine(value4);
Console.WriteLine(value5);
Console.WriteLine(value6);
Console.WriteLine(value7);
Console.WriteLine(value8);
Console.WriteLine(value9);
Console.WriteLine(value10);
Console.WriteLine(value11);
Console.WriteLine(value12);
Console.WriteLine(value13);
Console.WriteLine(value14);
Console.WriteLine(value15);
Console.WriteLine(value16);4 Two squared.
9 Three squared.
16 Four squared.
25 Five squared.
8 Two cubed (2 * 2 * 2).
27 Three cubed (3 * 3 * 3).
64 Four cubed (4 * 4 * 4).
125 Five cubed (5 * 5 * 5).
Infinity
1
NaN
Infinity
Infinity
4.28709385014517
7.38905609893065
3.14159265358979

Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.

Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.

This page was last updated on Sep 6, 2023 (edit).