Está en la página 1de 68

Nombre del Estudiante: Orbin Daniel Morales López

Número de Cuenta: 1220207

Nombre del Catedrático/a: Lic. Eldrin Salomón Mejía Guzmán

Sección: 1

Horario de Clase: 6:10 PM – 9:10 PM

Asignatura: Programación I

Fecha de Elaboración: 14/09/2022

1
Métodos Math o Matemáticos en Microsoft Visual C#

 Método Math.Abs: Devuelve el valor absoluto de un número


especificado.

La Sintaxis del Método Math.Abs es la siguiente:

public static decimal Abs (decimal val);

 Ejemplo:

// C# Program to illlustrate the

// Math.Abs(Decimal) Method

using System;

class Geeks {

// Main Method

public static void Main()

// Taking decimal values

decimal[] deci = {Decimal.MinValue, 45.14M, 0M,

-17.47M, Decimal.MaxValue};

// using foreach loop

foreach(decimal value in deci)

// Displaying the result

2
Console.WriteLine("Absolute value of {0} = {1}",

value,
Math.Abs(value));

 Método Math.Acos: Devuelve el ángulo cuyo coseno es el número


especificado.

La Sintaxis del Método Math.Acos es la siguiente:

public static double Acos(double num)

 Ejemplo:

// C# program to demonstrate working

// of Math.Acos() method

using System;

class Geeks {

// Main Method

public static void Main(String[] args)

double a = Math.PI;

// using Math.Acos() method

Console.WriteLine(Math.Acos(a));

// argument is greater than 1

3
Console.WriteLine(Math.Acos(2));

Console.WriteLine(Math.Acos(0.3584));

double d = 0.0;

double e = -0.0;

double posi = Double.PositiveInfinity;

double nega = Double.NegativeInfinity;

double nan = Double.NaN;

// Input positive zero

// Output 1.5707963267949

double res = Math.Acos(d);

// converting to degree

// i.e output will be 90 degree

double rest = res * (180 / Math.PI);

Console.WriteLine(rest);

// Input negative zero

// Output 1.5707963267949

Console.WriteLine(Math.Acos(e));

// input PositiveInfinity

4
// Output NaN

Console.WriteLine(Math.Acos(posi));

// input NegativeInfinity

// Output NaN

Console.WriteLine(Math.Acos(nega));

// input NaN

// Output NaN

Console.WriteLine(Math.Acos(nan));

 Método Math.Acosh: Devuelve el ángulo cuyo coseno hiperbólico es el


número especificado.

La Sintaxis del Método Math.Acosh es la siguiente:

public static float Acosh (float x);

 Ejemplo:

// C# program to demonstrate the

// MathF.Acosh(Single) Method

using System;

class GFG {

// Main Method

public static void Main()

5
{

// Declaring and initializing value

float value = 2.5f;

// getting hyperbolic arc-cosine value

// using Acosh() method

float result = MathF.Acosh(value);

// Display the value

Console.WriteLine("Angle is {0}", result);

 Método Math.Asin: Devuelve el ángulo cuyo seno es el número


especificado.

La Sintaxis del Método Math.Asin es la siguiente:

public static double Asin(double num)

 Ejemplo:

// C# program to demonstrate working

// of Math.Asin() method

using System;

class Geeks {

// Main Method

6
public static void Main(String[] args)

double a = Math.PI;

// using Math.Asin() method

Console.WriteLine(Math.Asin(a));

// argument is greater than 1

Console.WriteLine(Math.Asin(2));

Console.WriteLine(Math.Asin(0.3584));

double d = 0.0;

double e = -0.0;

double posi = Double.PositiveInfinity;

double nega = Double.NegativeInfinity;

double nan = Double.NaN;

// Input positive zero

// Output 0

double res = Math.Asin(d);

// converting to degree

// i.e. output is 0 degree

7
double rest = res * (180 / Math.PI);

Console.WriteLine(rest);

// Input negative zero

// Output 0

Console.WriteLine(Math.Asin(e));

// input PositiveInfinity

// Output NaN

Console.WriteLine(Math.Asin(posi));

// input NegativeInfinity

// Output NaN

Console.WriteLine(Math.Asin(nega));

// input NaN

// Output NaN

Console.WriteLine(Math.Asin(nan));

 Método Math.Asinh: El método Math.Asinh se utiliza para devolver el


arco-seno hiperbólico de un valor de coma flotante.

La Sintaxis del Método Math.Asinh es la siguiente:

Math.Asinh(Double d)

 Ejemplo:

8
// C# program to demonstrate the

// MathF.Asinh(Single) Method

using System;

class GFG {

// Main Method

public static void Main()

// Declaring and initializing value

float value = 1.5f;

// getting hyperbolic arc-cosine value

// using Asinh() method

float result = MathF.Asinh(value);

// Display the value

Console.WriteLine("Angle is {0}", result);

 Método Math.Atan: Devuelve el ángulo cuya tangente corresponde al


número especificado.

La Sintaxis del Método Math.Atan es la siguiente:

public static double Atan(double num)

9
 Ejemplo

// C# program to demonstrate working

// of Math.Atan() method

using System;

class Geeks {

// Main Method

public static void Main(String []args)

double a = Math.PI;

// using Math.Atan() method

Console.WriteLine(Math.Atan(a));

double d = 0.0;

double e = -0.0;

double posi = Double.PositiveInfinity;

double nega = Double.NegativeInfinity;

double nan = Double.NaN;

Console.WriteLine(Math.Atan(1));

// Input positive zero

10
// Output positive zero

Console.WriteLine(Math.Atan(d));

// Input negative zero

// Output positive zero

Console.WriteLine(Math.Atan(e));

// input PositiveInfinity

// Output 1.5707963267949

Console.WriteLine(Math.Atan(posi));

// input NegativeInfinity

// Output -1.5707963267949

Console.WriteLine(Math.Atan(nega));

// input NaN

// Output NaN

Console.WriteLine(Math.Atan(nan));

 Método Math.Atan2: Devuelve el ángulo cuya tangente es el cociente


de dos números especificados.

La Sintaxis del Método Math.Atan2 es la siguiente:

public static double Atan2(double value1, double value2)

 Ejemplo:

11
// C# program to demonstrate the

// Math.Atan2() Method when point

// lies in first quadrant

using System;

class Geeks {

// Main method

public static void Main()

// using Math.Atan2() Method &

// converting result into degree

Console.Write(Math.Atan2(10, 10) * (180 / Math.PI));

 Método Math.Atanh: Devuelve el ángulo cuya tangente hiperbólica es


el número especificado.

La Sintaxis del Método Math.Atanh es la siguiente:

Math.Atanh(Double d);

 Ejemplo:

using System;

class Example {

static void Main(string[] args) {

Double d, result;

12
d = Double.NegativeInfinity;

result = Math.Atanh(d);

Console.WriteLine($"Atanh({d}) = {result} radians.");

d = -5;

result = Math.Atanh(d);

Console.WriteLine($"Atanh({d}) = {result} radians.");

d = -1;

result = Math.Atanh(d);

Console.WriteLine($"Atanh({d}) = {result} radians.");

d = 0;

result = Math.Atanh(d);

Console.WriteLine($"Atanh({d}) = {result} radians.");

d = 1;

result = Math.Atanh(d);

Console.WriteLine($"Atanh({d}) = {result} radians.");

d = 5;

result = Math.Atanh(d);

Console.WriteLine($"Atanh({d}) = {result} radians.");

13
d = Double.PositiveInfinity;

result = Math.Atanh(d);

Console.WriteLine($"Atanh({d}) = {result} radians.");

 Método Math.BigMul: En C#, BigMul() es un método de clase de


método. Este método se utiliza para calcular el producto completo de
dos números de 32 bits.

La Sintaxis del Método Math.BigMul es la siguiente:

public static long BigMul(int a, int b);

 Ejemplo:

// C# program to demonstrate the

// Math.BigMul() method

using System;

namespace ConsoleApplication1 {

class Geeks {

// Main Method

static void Main(string[] args)

// defining two variable of type

// System.Int32

Int32 x1 = 233232322;

14
Int32 x2 = 189222338;

// Using BigMul( ) method and storing

// result into a long(Int64) variable

long product = Math.BigMul(x1, x2);

// Getting the output

Console.WriteLine("The product of the two numbers is " +


product);

 Método Math.BitDecrement: Devuelve el siguiente valor más pequeño


menor que x.

La Sintaxis del Método Math.BitDecrement es la siguiente:

Math.BitDecrement(Double x);

 Ejemplo:

using System;

class Example {

static void Main(string[] args) {

Double x, result;

x = 12.56;

result = Math.BitDecrement(x);

15
Console.WriteLine($"BitDecrement({x}) = {result}");

x = 10;

result = Math.BitDecrement(x);

Console.WriteLine($"BitDecrement({x}) = {result}");

 Método Math.BitIncrement: Devuelve el siguiente valor más grande


mayor que x.

La Sintaxis del Método Math.BitIncrement es la siguiente:

Math.BitIncrement(Double x);

 Ejemplo:

using System;

class Example {

static void Main(string[] args) {

Double x, result;

x = 12.56;

result = Math.BitIncrement(x);

Console.WriteLine($"BitIncrement({x}) = {result}");

x = 10;

result = Math.BitIncrement(x);

Console.WriteLine($"BitIncrement({x}) = {result}");

16
}

 Método Math.Cbrt: Devuelve la raíz cúbica de un número especificado.

La Sintaxis del Método Math.Cbrt es la siguiente:

Math.Cbrt(Double d);

 Ejemplo:

using System;

class Example {

static void Main(string[] args) {

Double d, result;

d = 2;

result = Math.Cbrt(d);

Console.WriteLine($"Cbrt({d}) = {result}");

d = 3;

result = Math.Cbrt(d);

Console.WriteLine($"Cbrt({d}) = {result}");

d = 4;

result = Math.Cbrt(d);

Console.WriteLine($"Cbrt({d}) = {result}");

17
d = 27;

result = Math.Cbrt(d);

Console.WriteLine($"Cbrt({d}) = {result}");

d = 64;

result = Math.Cbrt(d);

Console.WriteLine($"Cbrt({d}) = {result}");

d = 0.008;

result = Math.Cbrt(d);

Console.WriteLine($"Cbrt({d}) = {result}");

d = -27;

result = Math.Cbrt(d);

Console.WriteLine($"Cbrt({d}) = {result}");

d = Double.NegativeInfinity;

result = Math.Cbrt(d);

Console.WriteLine($"Cbrt({d}) = {result}");

d = Double.PositiveInfinity;

result = Math.Cbrt(d);

Console.WriteLine($"Cbrt({d}) = {result}");

}
18
 Método Math.Ceiling: Devuelve el menor valor integral mayor o igual
que el número especificado.

La Sintaxis del Método Math.Ceiling es la siguiente:

public static decimal Ceiling(decimal d);

 Ejemplo:

// C# program to illustrate the

// Math.Ceiling(Decimal) function

using System;

class SudoPlacement {

// Main method

static void Main()

// Input decimal value.

decimal decim_n1 = 2.10M;

decimal decim_n2 = -99.90M;

decimal decim_n3 = 33.001M;

// Calculate Ceiling values by

// Using Math.Ceiling() function

decimal ceil_t1 = Math.Ceiling(decim_n1);

decimal ceil_t2 = Math.Ceiling(decim_n2);

decimal ceil_t3 = Math.Ceiling(decim_n3);

19
// Print First values and Ceiling

Console.WriteLine("Input Value = " + decim_n1);

Console.WriteLine("Ceiling value = " + ceil_t1);

// Print Second values and Ceiling

Console.WriteLine("Input Value = " + decim_n2);

Console.WriteLine("Ceiling value = " + ceil_t2);

// Print third values and Ceiling

Console.WriteLine("Input Value = " + decim_n3);

Console.WriteLine("Ceiling value = " + ceil_t3);

 Método Math.Clamp: El método C# Clamp() devuelve el valor fijado al


rango inclusivo de mínimo y máximo.

La Sintaxis del Método Math.Clamp es la siguiente:

Math.Clamp(Byte value, Byte min, Byte max);

 Ejemplo:

using System;

class MyProgram {

static void Main(string[] args) {

Console.WriteLine("Math.Clamp(25, 50, 100): "+

Math.Clamp(25, 50, 100));

20
Console.WriteLine("Math.Clamp(25, 0, 50): "+

Math.Clamp(25, 0, 50));

Console.WriteLine("Math.Clamp(25, -25, 0): "+

Math.Clamp(25, -25, 0));

 Método Math.CopySign: Devuelve un valor con la magnitud de x y el


signo de y.

La Sintaxis del Método Math.CopySign es la siguiente:

Math.CopySign(Double x, Double y);

 Ejemplo:

using System;

class Example {

static void Main(string[] args) {

Double x, y, result;

x = 2;

y = -8;

result = Math.CopySign(x, y);

Console.WriteLine($"CopySign({x}, {y}) = {result}");

x = 2;

y = 8;

result = Math.CopySign(x, y);

21
Console.WriteLine($"CopySign({x}, {y}) = {result}");

x = -2;

y = 8;

result = Math.CopySign(x, y);

Console.WriteLine($"CopySign({x}, {y}) = {result}");

 Método Math.Cos: Devuelve el coseno del ángulo especificado.

La Sintaxis del Método Math.Cos es la siguiente:

public static double Cos(double num);

 Ejemplo:

// C# program to demonstrate working

// Math.Cos() method

using System;

class Geeks {

// Main Method

public static void Main(String []args)

double a = 70;

// converting value to radians

22
double b = (a * (Math.PI)) / 180;

// using method and displaying result

Console.WriteLine(Math.Cos(b));

a = 50;

// converting value to radians

b = (a * (Math.PI)) / 180;

// using method and displaying result

Console.WriteLine(Math.Cos(b));

a = 73;

// converting value to radians

b = (a * (Math.PI)) / 180;

// using method and displaying result

Console.WriteLine(Math.Cos(b));

a = 77;

// converting value to radians

b = (a * (Math.PI)) / 180;

// using method and displaying result

23
Console.WriteLine(Math.Cos(b));

 Método Math.Cosh: Devuelve el coseno hiperbólico del ángulo


especificado.

La Sintaxis del Método Math.Cosh es la siguiente:

public static double Cosh(double num);

 Ejemplo:

// C# program to illustrate the

// Math.Cosh()

using System;

class GFG {

// Main Method

public static void Main(String[] args)

double num1 = 60.0, num2 = 0.0, num3 = 1.0;

// It returns the hyperbolic cosine of

// specified angle in radian

double coshvalue = Math.Cosh(num1);

Console.WriteLine("The cosh of num1 = " + coshvalue);

24
coshvalue = Math.Cosh(num2);

Console.WriteLine("The cosh of num2 = " + coshvalue);

coshvalue = Math.Cosh(num3);

Console.WriteLine("The cosh of num3 = " + coshvalue);

 Método Math.DivRem: Calcula el cociente de dos números y devuelve


también el resto de la división como parámetro de salida.

La Sintaxis del Método Math.DivRem es la siguiente:

public static int DivRem(int dividend, int divisor, int result);

 Ejemplo:

// C# program to demonstrate working

// of Math.DivRem(Int32, Int32, Int32)

using System;

class DivRemGeeks {

// Main method

static void Main()

// Input +ve dividend and divisor number

int dividend_A = 9845324;

int divisor_A = 7;

25
// Input negative dividend and divisor number

int dividend_B = -99999;

int divisor_B = 2;

int result_1;

int result_2;

// Using the MATH.DivRem() Method

int quotient_ONE = Math.DivRem(dividend_A, divisor_A, out


result_1);

int quotient_TWO = Math.DivRem(dividend_B, divisor_B, out


result_2);

// Print Result

Console.WriteLine(quotient_ONE);

Console.WriteLine(result_1);

Console.WriteLine(quotient_TWO);

Console.WriteLine(result_2);

 Método Math.Exp: Devuelve e elevado a la potencia especificada.

La Sintaxis del Método Math.Exp es la siguiente:

public static double Exp (double num);

 Ejemplo:

26
// C# Program to illustrate the

// Math.Exp(Double) Method

using System;

class Geeks {

// Main Method

public static void Main()

// using the method

Console.WriteLine(Math.Exp(10.0));

Console.WriteLine(Math.Exp(15.57));

Console.WriteLine(Math.Exp(529.548));

Console.WriteLine(Math.Exp(0.00));

 Método Math.Floor: Devuelve el mayor valor integral menor o igual que


el número especificado.

La Sintaxis del Método Math.Floor es la siguiente:

public static decimal Floor(decimal d);

 Ejemplo:

// C# program to illustrate the

// Math.Floor(Decimal) function

using System;

27
public class GFG {

// Main method

static public void Main()

// Different numbers list to find

// its floor values

Console.WriteLine(Math.Floor(0.2018));

Console.WriteLine(Math.Floor(123.123));

Console.WriteLine(Math.Floor(-0.2));

Console.WriteLine(Math.Floor(0.0));

Console.WriteLine(Math.Floor(34.67M));

 Método Math.FusedMultiplyAdd: Devuelve (x * y) + z, redondeado


como una operación ternaria.

La Sintaxis del Método Math.FusedMultiplyAdd es la siguiente:

Math.FusedMultiplyAdd(Double x, Double y, Double z);

 Ejemplo:

using System;

class Example {

static void Main(string[] args) {

28
Double x, y, z, result;

x = 2;

y = 3;

z = 1;

result = Math.FusedMultiplyAdd(x, y, z);

Console.WriteLine($"FusedMultiplyAdd({x}, {y}, {z}) = {result}");

x = 10;

y = 5;

z = 3;

result = Math.FusedMultiplyAdd(x, y, z);

Console.WriteLine($"FusedMultiplyAdd({x}, {y}, {z}) = {result}");

 Método Math.IEEERemainder: Devuelve el resto de la división de dos


números especificados.

La Sintaxis del Método Math.IEEERemainder es la siguiente:

public static double IEEERemainder (double a, double b);

 Ejemplo:

// C# Program to illustrate the

// Math.IEEERemainder() Method

using System;

class Geeks

29
{

// method to calculate the remainder

private static void DisplayRemainder(double num1, double num2)

var calculation = $"{num1} / {num2} = ";

// calculating IEEE Remainder

var ieeerem = Math.IEEERemainder(num1, num2);

// using remainder operator

var rem_op = num1 % num2;

Console.WriteLine($"{calculation,-16} {ieeerem,18} {rem_op,20}");

// Main Method

public static void Main()

Console.WriteLine($"{"IEEERemainder",35} {"Remainder Operator",20}");

30
// calling the method

DisplayRemainder(0, 1);

DisplayRemainder(-4, 8);

DisplayRemainder(1, 0);

DisplayRemainder(-1, -0);

DisplayRemainder(145, 7);

DisplayRemainder(18.52, 2);

DisplayRemainder(42.26, 4.2);

 Método Math.ILogB: Devuelve el logaritmo de entero en base 2 de un


número especificado.

La Sintaxis del Método Math.ILogB es la siguiente:

Math.ILogB(Double x);

 Ejemplo:

using System;

class Example {

static void Main(string[] args) {

Double x;

Double result;

x = 2;

result = Math. ILogB(x);

Console.WriteLine($"ILogB({x}) = {result}");

31
x = 3;

result = Math. ILogB(x);

Console.WriteLine($"ILogB({x}) = {result}");

x = 4;

result = Math. ILogB(x);

Console.WriteLine($"ILogB({x}) = {result}");

 Método Math.Log: En C#, Math.Log() es un método de clase Math. Se


utiliza para devolver el logaritmo de un número especificado.

La Sintaxis del Método Math.Log es la siguiente:

public static double Log(double val);

 Ejemplo:

// C# program to demonstrate working

// of Math.Log(Double) method

using System;

class Geeks {

// Main Method

public static void Main(String[] args)

32
// double values whose logarithm

// to be calculated

double a = 4.55;

double b = 0;

double c = -2.45;

double nan = Double.NaN;

double positiveInfinity = Double.PositiveInfinity;

double negativeInfinity = Double.NegativeInfinity;

// Input is positive number so output

// will be logarithm of number

Console.WriteLine(Math.Log(a));

// positive zero as argument, so output

// will be -Infinity

Console.WriteLine(Math.Log(b));

// Input is negative number so output

// will be NaN

Console.WriteLine(Math.Log(c));

// Input is NaN so output

// will be NaN

Console.WriteLine(Math.Log(nan));

33
// Input is PositiveInfinity so output

// will be Infinity

Console.WriteLine(Math.Log(positiveInfinity));

// Input is NegativeInfinity so output

// will be NaN

Console.WriteLine(Math.Log(negativeInfinity));

 Método Math.Log10: Devuelve el logaritmo en base 10 de un número


especificado.

La Sintaxis del Método Math.Log10 es la siguiente:

public static double Log10(double val);

 Ejemplo:

// C# program to demonstrate working

// of Math.Log10(Double) method

using System;

class Geeks {

// Main Method

public static void Main(String[] args)

34
// double values whose logarithm

// to be calculated

double a = 4.55;

double b = 0;

double c = -2.45;

double nan = Double.NaN;

double positiveInfinity = Double.PositiveInfinity;

double negativeInfinity = Double.NegativeInfinity;

// Input is positive number so output

// will be logarithm of number

Console.WriteLine(Math.Log10(a));

// positive zero as argument, so output

// will be -Infinity

Console.WriteLine(Math.Log10(b));

// Input is negative number so output

// will be NaN

Console.WriteLine(Math.Log10(c));

// Input is NaN so output

// will be NaN

Console.WriteLine(Math.Log10(nan));

35
// Input is PositiveInfinity so output

// will be Infinity

Console.WriteLine(Math.Log10(positiveInfinity));

// Input is NegativeInfinity so output

// will be NaN

Console.WriteLine(Math.Log10(negativeInfinity));

 Método Math.Log2: Devuelve el logaritmo en base 2 de un número


especificado.

La Sintaxis del Método Math.Log2 es la siguiente:

public static double Log2 (double arg);

 Ejemplo:

using System;

class MyProgram {

static void Main(string[] args) {

Console.WriteLine("Math.Log2(0) = "

+ Math.Log2(0));

Console.WriteLine("Math.Log2(10) = "

+ Math.Log2(10));

Console.WriteLine("Math.Log2(50) = "

+ Math.Log2(50));

36
Console.WriteLine("Math.Log2(Double.NaN) = "

+ Math.Log2(Double.NaN));

Console.WriteLine("Math.Log2(Double.NegativeInfinity) = "

+ Math.Log2(Double.NegativeInfinity));

Console.WriteLine("Math.Log2(Double.PositiveInfinity) = "

+ Math.Log2(Double.PositiveInfinity));

 Método Math.Max: Devuelve el mayor de dos números especificados.

La Sintaxis del Método Math.Max es la siguiente:

public static data_type Max(Data_type first_value, Data_type second_value);

 Ejemplo:

// C# program to demonstrate the

// Math.Max() method

using System;

class GFG {

// Main Method

static void Main()

// byte data type

byte b1 = 10, b2 = 15;

37
// decimal data type

decimal d1 = 1000M, d2 = 1568M;

// double data type

double db1 = 15.896745, db2 = 8.62644598;

// Int16 data type

short sh1 = -96, sh2 = 24;

// Int32 data type

int i1 = 26745236, i2 = 36725413;

// Int64 data type

long l1 = -2534234234234, l2 = -745837587527423;

// sbyte data type

sbyte sb1 = 52, sb2 = 120;

// single data type

float f1 = 8.0f, f2 = 78.78f;

// UInt16 data type

ushort us1 = 5346, us2 = 6437;


38
// UInt32 data type

uint un1 = 432344637, un2 = 64762738;

// UInt64 data type

ulong ul1 = 34234234, ul2 = 673286478326;

// displaying result

Console.WriteLine("Math.Max Method (Byte, Byte) = " + Math.Max(b1,


b2));

Console.WriteLine("Math.Max Method (Decimal, Decimal) = " +


Math.Max(d1, d2));

Console.WriteLine("Math.Max Method (Double, Double) = " +


Math.Max(db1, db2));

Console.WriteLine("Math.Max Method (Int16, Int16) = " + Math.Max(sh1,


sh2));

Console.WriteLine("Math.Max Method (Int32, Int32) = " + Math.Max(i1,


i2));

Console.WriteLine("Math.Max Method (Int64, lInt64) = " + Math.Max(l1,


l2));

Console.WriteLine("Math.Max Method (SByte, SByte) = " +


Math.Max(sb1, sb2));

Console.WriteLine("Math.Max Method (Single, Single) = " + Math.Max(f1,


f2));

Console.WriteLine("Math.Max Method (UInt16, UInt16) = " +


Math.Max(us1, us2));

39
Console.WriteLine("Math.Max Method (UInt32, UInt32) = " +
Math.Max(un1, un2));

Console.WriteLine("Math.Max Method (UInt64, UInt64) = " +


Math.Max(ul1, ul2));

 Método Math.MaxMagnitude: Devuelve la magnitud mayor de dos


números de punto flotante de precisión doble.

La Sintaxis del Método Math.MaxMagnitude es la siguiente:

public static double MaxMagnitude (double value1, double value2);

 Ejemplo:

using System;

class Educative

static void Main()

double result = Math.MaxMagnitude(20, 30);

System.Console.WriteLine("MaxMagnitude(20, 30) = "+ result);

double result1 = Math.MaxMagnitude(Double.NaN, 30);

System.Console.WriteLine("MaxMagnitude(NaN, 30) = "+ result1);

double result2 = Math.MaxMagnitude(20, -30);

System.Console.WriteLine("MaxMagnitude(20, -30) = "+ result2);

40
}

 Método Math.Min: Devuelve el menor de dos números.

La Sintaxis del Método Math.Min es la siguiente:

public static data_type Min(Data_type first_value, Data_type second_value);

 Ejemplo:

// C# program to demonstrate the

// Math.Min() method

using System;

class GFG {

// Main Method

static void Main()

// byte data type

byte b1 = 10, b2 = 15;

// decimal data type

decimal d1 = 1000M, d2 = 1568M;

// double data type

double db1 = 15.896745, db2 = 8.62644598;

41
// Int16 data type

short sh1 = -96, sh2 = 24;

// Int32 data type

int i1 = 26745236, i2 = 36725413;

// Int64 data type

long l1 = -2534234234234, l2 = -745837587527423;

// sbyte data type

sbyte sb1 = 52, sb2 = 120;

// single data type

float f1 = 8.0f, f2 = 78.78f;

// UInt16 data type

ushort us1 = 5346, us2 = 6437;

// UInt32 data type

uint un1 = 432344637, un2 = 64762738;

// UInt64 data type


42
ulong ul1 = 34234234, ul2 = 673286478326;

// displaying result

Console.WriteLine("Math.Min Method (Byte, Byte) = " + Math.Min(b1,


b2));

Console.WriteLine("Math.Min Method (Decimal, Decimal) = " +


Math.Min(d1, d2));

Console.WriteLine("Math.Min Method (Double, Double) = " +


Math.Min(db1, db2));

Console.WriteLine("Math.Min Method (Int16, Int16) = " + Math.Min(sh1,


sh2));

Console.WriteLine("Math.Min Method (Int32, Int32) = " + Math.Min(i1,


i2));

Console.WriteLine("Math.Min Method (Int64, lInt64) = " + Math.Min(l1,


l2));

Console.WriteLine("Math.Min Method (SByte, SByte) = " + Math.Min(sb1,


sb2));

Console.WriteLine("Math.Min Method (Single, Single) = " + Math.Min(f1,


f2));

Console.WriteLine("Math.Min Method (UInt16, UInt16) = " +


Math.Min(us1, us2));

Console.WriteLine("Math.Min Method (UInt32, UInt32) = " +


Math.Min(un1, un2));

Console.WriteLine("Math.Min Method (UInt64, UInt64) = " +


Math.Min(ul1, ul2));

}
43
}

 Método Math.MinMagnitude: Devuelve la magnitud menor de dos


números de punto flotante de precisión doble.

La Sintaxis del Método Math.MinMagnitude es la siguiente:

public static double MinMagnitude (double x, double y);

 Ejemplo:

// C# program to demonstrate the

// Math.Min() method

using System;

class GFG {

// Main Method

static void Main()

// byte data type

byte b1 = 10, b2 = 15;

// decimal data type

decimal d1 = 1000M, d2 = 1568M;

// double data type

double db1 = 15.896745, db2 = 8.62644598;

44
// Int16 data type

short sh1 = -96, sh2 = 24;

// Int32 data type

int i1 = 26745236, i2 = 36725413;

// Int64 data type

long l1 = -2534234234234, l2 = -745837587527423;

// sbyte data type

sbyte sb1 = 52, sb2 = 120;

// single data type

float f1 = 8.0f, f2 = 78.78f;

// UInt16 data type

ushort us1 = 5346, us2 = 6437;

// UInt32 data type

uint un1 = 432344637, un2 = 64762738;

// UInt64 data type

ulong ul1 = 34234234, ul2 = 673286478326;

45
// displaying result

Console.WriteLine("Math.Min Method (Byte, Byte) = " + Math.Min(b1,


b2));

Console.WriteLine("Math.Min Method (Decimal, Decimal) = " +


Math.Min(d1, d2));

Console.WriteLine("Math.Min Method (Double, Double) = " +


Math.Min(db1, db2));

Console.WriteLine("Math.Min Method (Int16, Int16) = " + Math.Min(sh1,


sh2));

Console.WriteLine("Math.Min Method (Int32, Int32) = " + Math.Min(i1,


i2));

Console.WriteLine("Math.Min Method (Int64, lInt64) = " + Math.Min(l1,


l2));

Console.WriteLine("Math.Min Method (SByte, SByte) = " + Math.Min(sb1,


sb2));

Console.WriteLine("Math.Min Method (Single, Single) = " + Math.Min(f1,


f2));

Console.WriteLine("Math.Min Method (UInt16, UInt16) = " +


Math.Min(us1, us2));

Console.WriteLine("Math.Min Method (UInt32, UInt32) = " +


Math.Min(un1, un2));

Console.WriteLine("Math.Min Method (UInt64, UInt64) = " +


Math.Min(ul1, ul2));

46
 Método Math.Pow: Devuelve un número especificado elevado a la
potencia especificada.

La Sintaxis del Método Math.Pow es la siguiente:

public static double Pow(double base, double power);

 Ejemplo:

// C# program to illustrate the

// Math.Pow() function

using System;

class GFG {

// Main Method

static public void Main()

// Find power using Math.Pow

// 6 is base and 2 is power or

// index or exponent of a number

double pow_ab = Math.Pow(6, 2);

// Print the result

Console.WriteLine(pow_ab);

// 3.5 is base and 3 is power or

// index or exponent of a number

double pow_tt = Math.Pow(3.5, 3);

47
// Print the result

Console.WriteLine(pow_tt);

// 202 is base and 4 is power or

// index or exponent of a number

double pow_t = Math.Pow(202, 4);

// Print the result

Console.WriteLine(pow_t);

 Método Math.ReciprocalEstimate: Devuelve una estimación de la


recíproca de un número especificado.

La Sintaxis del Método Math.ReciprocalEstimate es la siguiente:

public static double ReciprocalEstimate (double d);

 Ejemplo:

(double sin, double cos) = Math.SinCos(1.57);

Console.WriteLine($"Sin = {sin}\nCos = {cos}");

// Computes an approximate of 1 / x

double recEst = Math.ReciprocalEstimate(5);

Console.WriteLine($"Reciprocal estimate = {recEst}");

// Computes an approximate of 1 / Sqrt(x)

double recSqrtEst = Math.ReciprocalSqrtEstimate(5);

Console.WriteLine($"Reciprocal sqrt estimate = {recSqrtEst}");

48
// New overloads

// Min, Max, Abs, Clamp and Sign supports nint and nuint

(nint a, nint b) = (5, 10);

nint min = Math.Min(a, b);

nint max = Math.Max(a, b);

nint abs = Math.Abs(a);

nint clamp = Math.Clamp(abs, min, max);

nint sign = Math.Sign(a);

Console.WriteLine($"Min = {min}\nMax = {max}\nAbs = {abs}");

Console.WriteLine($"Clamp = {clamp}\nSign = {sign}");

// DivRem variants return a tuple

(int quotient, int remainder) = Math.DivRem(2, 7);

Console.WriteLine($"Quotient = {quotient}\nRemainder = {remainder}");

 Método Math.ReciprocalSqrtEstimate: Devuelve una estimación de la


raíz cuadrada recíproca de un número especificado.

La Sintaxis del Método Math.ReciprocalSqrtEstimate es la siguiente:

public static double ReciprocalSqrtEstimate (double d);

 Ejemplo

// New methods SinCos, ReciprocalEstimate and ReciprocalSqrtEstimate

// Simultaneously computes Sin and Cos

(double sin, double cos) = Math.SinCos(1.57);

Console.WriteLine($"Sin = {sin}\nCos = {cos}");

// Computes an approximate of 1 / x

49
double recEst = Math.ReciprocalEstimate(5);

Console.WriteLine($"Reciprocal estimate = {recEst}");

// Computes an approximate of 1 / Sqrt(x)

double recSqrtEst = Math.ReciprocalSqrtEstimate(5);

Console.WriteLine($"Reciprocal sqrt estimate = {recSqrtEst}");

// New overloads

// Min, Max, Abs, Clamp and Sign supports nint and nuint

(nint a, nint b) = (5, 10);

nint min = Math.Min(a, b);

nint max = Math.Max(a, b);

nint abs = Math.Abs(a);

nint clamp = Math.Clamp(abs, min, max);

nint sign = Math.Sign(a);

Console.WriteLine($"Min = {min}\nMax = {max}\nAbs = {abs}");

Console.WriteLine($"Clamp = {clamp}\nSign = {sign}");

// DivRem variants return a tuple

(int quotient, int remainder) = Math.DivRem(2, 7);

Console.WriteLine($"Quotient = {quotient}\nRemainder = {remainder}");

// Output:

// Sin = 0.9999996829318346

50
// Cos = 0.0007963267107331026

// Reciprocal estimate = 0.2

// Reciprocal sqrt estimate = 0.4472135954999579

// Min = 5

// Max = 10

// Abs = 5

// Clamp = 5

// Sign = 1

// Quotient = 0

// Remainder = 2

 Método Math.Round: Redondea un valor al entero más próximo o al


número especificado de dígitos fraccionarios.

La Sintaxis del Método Math.Round es la siguiente:

public static double Round(double x)

 Ejemplo:

// C# program to demonstrate the

// Math.Round(Double) method

using System;

class Geeks {

// Main method

static void Main(string[] args)

51
// Case-1

// A double value whose fractional part is

// less than the halfway between two

// consecutive integers

Double dx1 = 12.434565d;

// Output value will be 12

Console.WriteLine("Rounded value of " + dx1 +

" is " + Math.Round(dx1));

// Case-2

// A double value whose fractional part is

// greater than the halfway between two

// consecutive integers

Double dx2 = 12.634565d;

// Output value will be 13

Console.WriteLine("Rounded value of " + dx2 +

" is " + Math.Round(dx2));

 Método Math.ScaleB: Devuelve x * 2^n calculado de forma eficaz.

La Sintaxis del Método Math.ScaleB es la siguiente:

public static double ScaleB (double a, int b);

52
 Ejemplo:

using System;

class MyProgram {

static void Main(string[] args) {

Console.WriteLine("Math.ScaleB(2.55, 4) = "

+ Math.ScaleB(2.55, 4));

Console.WriteLine("Math.ScaleB(10, 3) = "

+ Math.ScaleB(10, 3));

Console.WriteLine("Math.ScaleB(Double.NaN, 3) = "

+ Math.ScaleB(Double.NaN, 3));

Console.WriteLine("Math.ScaleB(Double.PositiveInfinity, 3) = "

+ Math.ScaleB(Double.PositiveInfinity, 3));

 Método Math.Sign: Devuelve un entero que indica el signo de un


número.

La Sintaxis del Método Math.Sign es la siguiente:

public static int Sign(data_type value);

 Ejemplo:

// C# program to demonstrate the

// Math.Sign() method

using System;

class GFG {

53
// Main Method

static void Main(string[] args)

// Decimal data type

Decimal de = 150M;

// Double data type

Double d = 34.5432d;

// Int16 data type

short sh = 0;

// Int32 data type

int i = -5678;

// Int64 data type

long l = 598964564;

// SByte data type

sbyte sb = -34;

// float data type

float f = 56.89f;
54
// displaying result

Console.WriteLine("Decimal: " + de + " " + check(Math.Sign(de)));

Console.WriteLine("Double: " + d + " " + check(Math.Sign(d)));

Console.WriteLine("Int16: " + sh + " " + check(Math.Sign(sh)));

Console.WriteLine("Int32: " + i + " " + check(Math.Sign(i)));

Console.WriteLine("Int64: " + l + " " + check(Math.Sign(l)));

Console.WriteLine("SByte: " + sb + " " + check(Math.Sign(sb)));

Console.WriteLine("Single: " + f + " " + check(Math.Sign(f)));

// function to check whether the input

// number is greater than zero or not

public static String check(int compare)

if (compare == 0)

return "equal to zero";

else if (compare < 0)

return "less than zero";

else

55
return "greater than zero";

 Método Math.Sin: Devuelve el seno del ángulo especificado.

La Sintaxis del Método Math.Sin es la siguiente:

public static double Sin(double num)

 Ejemplo:

// C# program to demonstrate working

// Math.Sin() method

using System;

class Geeks {

// Main Method

public static void Main(String []args)

double a = 30;

// converting value to radians

double b = (a * (Math.PI)) / 180;

// using method and displaying result

Console.WriteLine(Math.Sin(b));

a = 45;

56
// converting value to radians

b = (a * (Math.PI)) / 180;

// using method and displaying result

Console.WriteLine(Math.Sin(b));

a = 60;

// converting value to radians

b = (a * (Math.PI)) / 180;

// using method and displaying result

Console.WriteLine(Math.Sin(b));

a = 90;

// converting value to radians

b = (a * (Math.PI)) / 180;

// using method and displaying result

Console.WriteLine(Math.Sin(b));

 Método Math.SinCos: Devuelve el seno y el coseno del ángulo


especificado.

La Sintaxis del Método Math.SinCos es la siguiente:

57
public static (double Sin, double Cos) SinCos (double x);

 Ejemplo:

// Example for the trigonometric Math.Sin( double )

// and Math.Cos( double ) methods.

using System;/* ww w .d em o 2 s . c o m */

class SinCos

public static void Main()

Console.WriteLine(

"This example of trigonometric " +

"Math.Sin( double ), Math.Cos( double ), and Math.SinCos( double )\n" +

"generates the following output.\n" );

Console.WriteLine(

"Convert selected values for X to radians \n" +

"and evaluate these trigonometric identities:" );

Console.WriteLine( " sin^2(X) + cos^2(X) == 1\n" +

" sin(2 * X) == 2 * sin(X) * cos(X)" );

Console.WriteLine( " cos(2 * X) == cos^2(X) - sin^2(X)" );

Console.WriteLine( " cos(2 * X) == cos^2(X) - sin^2(X)" );

UseSineCosine(15.0);

UseSineCosine(30.0);

UseSineCosine(45.0);

Console.WriteLine(

58
"\nConvert selected values for X and Y to radians \n" +

"and evaluate these trigonometric identities:" );

Console.WriteLine( " sin(X + Y) == sin(X) * cos(Y) + cos(X) * sin(Y)" );

Console.WriteLine( " cos(X + Y) == cos(X) * cos(Y) - sin(X) * sin(Y)" );

UseTwoAngles(15.0, 30.0);

UseTwoAngles(30.0, 45.0);

Console.WriteLine(

"\nWhen you have calls to sin(X) and cos(X) they \n" +

"can be replaced with a single call to sincos(x):" );

UseCombinedSineCosine(15.0);

UseCombinedSineCosine(30.0);

UseCombinedSineCosine(45.0);

// Evaluate trigonometric identities with a given angle.

static void UseCombinedSineCosine(double degrees)

double angle = Math.PI * degrees / 180.0;

(double sinAngle, double cosAngle) = Math.SinCos(angle);

// Evaluate sin^2(X) + cos^2(X) == 1.

Console.WriteLine(

"\n Math.SinCos({0} deg) == ({1:E16}, {2:E16})",

degrees, sinAngle, cosAngle);

Console.WriteLine(

"(double sin, double cos) = Math.SinCos({0} deg)",

59
degrees );

Console.WriteLine(

"sin^2 + cos^2 == {0:E16}",

sinAngle * sinAngle + cosAngle * cosAngle );

// Evaluate trigonometric identities with a given angle.

static void UseSineCosine(double degrees)

double angle = Math.PI * degrees / 180.0;

double sinAngle = Math.Sin(angle);

double cosAngle = Math.Cos(angle);

// Evaluate sin^2(X) + cos^2(X) == 1.

Console.WriteLine(

"\n Math.Sin({0} deg) == {1:E16}\n" +

" Math.Cos({0} deg) == {2:E16}",

degrees, Math.Sin(angle), Math.Cos(angle) );

Console.WriteLine(

"(Math.Sin({0} deg))^2 + (Math.Cos({0} deg))^2 == {1:E16}",

degrees, sinAngle * sinAngle + cosAngle * cosAngle );

// Evaluate sin(2 * X) == 2 * sin(X) * cos(X).

Console.WriteLine(

" Math.Sin({0} deg) == {1:E16}",

2.0 * degrees, Math.Sin(2.0 * angle) );

Console.WriteLine(

60
" 2 * Math.Sin({0} deg) * Math.Cos({0} deg) == {1:E16}",

degrees, 2.0 * sinAngle * cosAngle );

// Evaluate cos(2 * X) == cos^2(X) - sin^2(X).

Console.WriteLine(

" Math.Cos({0} deg) == {1:E16}",

2.0 * degrees, Math.Cos(2.0 * angle) );

Console.WriteLine(

"(Math.Cos({0} deg))^2 - (Math.Sin({0} deg))^2 == {1:E16}",

degrees, cosAngle * cosAngle - sinAngle * sinAngle );

// Evaluate trigonometric identities that are functions of two angles.

static void UseTwoAngles(double degreesX, double degreesY)

double angleX = Math.PI * degreesX / 180.0;

double angleY = Math.PI * degreesY / 180.0;

// Evaluate sin(X + Y) == sin(X) * cos(Y) + cos(X) * sin(Y).

Console.WriteLine(

"\n Math.Sin({0} deg) * Math.Cos({1} deg) +\n" +

" Math.Cos({0} deg) * Math.Sin({1} deg) == {2:E16}",

degreesX, degreesY, Math.Sin(angleX) * Math.Cos(angleY) +

Math.Cos(angleX) * Math.Sin(angleY));

Console.WriteLine(

" Math.Sin({0} deg) == {1:E16}",

degreesX + degreesY, Math.Sin(angleX + angleY));

61
// Evaluate cos(X + Y) == cos(X) * cos(Y) - sin(X) * sin(Y).

Console.WriteLine(

" Math.Cos({0} deg) * Math.Cos({1} deg) -\n" +

" Math.Sin({0} deg) * Math.Sin({1} deg) == {2:E16}",

degreesX, degreesY, Math.Cos(angleX) * Math.Cos(angleY) -

Math.Sin(angleX) * Math.Sin(angleY));

Console.WriteLine(

" Math.Cos({0} deg) == {1:E16}",

degreesX + degreesY, Math.Cos(angleX + angleY));

 Método Math.Sinh: Devuelve el seno hiperbólico del ángulo


especificado.

La Sintaxis del Método Math.Sinh es la siguiente:

public static double Sinh(double num);

 Ejemplo:

// C# program to illustrate the

// Math.Sinh()

using System;

class GFG {

// Main Method

public static void Main(String[] args)

62
double num1 = 78.8, num2 = 0.0, num3 = 1.0;

// It returns the hyperbolic sine of specified

// angle in radian

double sinhvalue = Math.Sinh(num1);

Console.WriteLine("The sinh of num1 = " + sinhvalue);

sinhvalue = Math.Sinh(num2);

Console.WriteLine("The sinh of num2 = " + sinhvalue);

sinhvalue = Math.Sinh(num3);

Console.WriteLine("The sinh of num3 = " + sinhvalue);

 Método Math.Sqrt: Devuelve la raíz cuadrada de un número


especificado.

La Sintaxis del Método Math.Sqrt es la siguiente:

public static double Sqrt (double value);

 Ejemplo:

using System;

class Educative

static void Main()

63
Double result = Math.Sqrt(-0.16);

System.Console.WriteLine("Sqrt(0.16) = "+ result);

Double result1 = Math.Sqrt(0);

System.Console.WriteLine("Sqrt(0) = "+ result1);

Double result2 = Math.Sqrt(16);

System.Console.WriteLine("Sqrt(16) = "+ result2);

Double result3 = Math.Sqrt(Double.PositiveInfinity);

System.Console.WriteLine("Sqrt(∞) = "+ result3);

Double result4 = Math.Sqrt(Double.NegativeInfinity);

System.Console.WriteLine("Sqrt(-∞) = "+ result4);

 Método Math.Tan: Devuelve la tangente del ángulo especificado.

La Sintaxis del Método Math.Tan es la siguiente:

public static double Tan(double num);

 Ejemplo:

// C# program to demonstrate working

// Math.Tan() method

using System;

64
class Geeks {

// Main Method

public static void Main(String []args)

double a = 12;

// converting value to radians

double b = (a * (Math.PI)) / 180;

// using method and displaying result

Console.WriteLine(Math.Tan(b));

a = 63;

// converting value to radians

b = (a * (Math.PI)) / 180;

// using method and displaying result

Console.WriteLine(Math.Tan(b));

a = 187;

// converting value to radians

b = (a * (Math.PI)) / 180;

65
// using method and displaying result

Console.WriteLine(Math.Tan(b));

a = 45;

// converting value to radians

b = (a * (Math.PI)) / 180;

// using method and displaying result

Console.WriteLine(Math.Tan(b));

 Método Math.Tanh: El método Math.Tanh() en C# se usa para devolver


la tangente hiperbólica del ángulo especificado.

La Sintaxis del Método Math.Tanh es la siguiente:

Math.Tanh(Double value);

 Ejemplo:

using System;

class Example {

static void Main(string[] args) {

Double value, result;

value = 1; //1 radian

result = Math.Tanh(value);

Console.WriteLine($"Tanh({value} radian) = {result}.");

66
value = Math.PI; // PI radians or 180 degrees

result = Math.Tanh(value);

Console.WriteLine($"Tanh({value} radian) = {result}.");

value = Math.PI/2; // 90 degrees

result = Math.Tanh(value);

Console.WriteLine($"Tanh({value} radian) = {result}.");

value = 0; // 0 degrees

result = Math.Tanh(value);

Console.WriteLine($"Tanh({value} radian) = {result}.");

value = Double.PositiveInfinity;

result = Math.Tanh(value);

Console.WriteLine($"Tanh({value} radian) = {result}.");

value = Double.NegativeInfinity;

result = Math.Tanh(value);

Console.WriteLine($"Tanh({value} radian) = {result}.");

 Math.Truncate: Calcula la parte entera de un número.

La Sintaxis del Método Math.Truncate es la siguiente:

public static decimal Truncate(decimal dec);


67
 Ejemplo:

// C# Program to illustrate the

// Math.Truncate(Decimal) Method

using System;

class Geeks {

// Main Method

public static void Main()

// variables of Decimal type

Decimal dec = 45.89511m;

Decimal dec2 = 54569.478021m;

// using function and displaying result

Console.WriteLine(Math.Truncate(dec));

Console.WriteLine(Math.Truncate(dec2));

68

También podría gustarte