Operations with Doubles

Tango.CommonOperations.DoubleOperations

This static class contains methods and properties to expose common operations to work with double types.

All members bellow returns the corresponding functions as delegates.

WARNING

All operations classes related to numerical values (int, decimal e double) contains the same properties and methods.

Properties

Name

Type

Description

Add

Func<double, double, double>

Function to represents addition operation (+) between two values.

Subtract

Func<double, double, double>

Function to represents subtraction operation (-) between two values.

Multiply

Func<double, double, double>

Function to represents multiplication operation (*) between two values.

Divide

Func<double, double, double>

Function to represents division operation (/) between two values.

Add3

Func<double, double, double, double>

Function to represents addition operation (+) between three values.

Subtract3

Func<double, double, double, double>

Function to represents subtraction operation (-) between three values.

Multiply3

Func<double, double, double, double>

Function to represents multiplication operation (*) between three values.

Divide3

Func<double, double, double, double>

Function to represents division operation (/) between three values.

Methods

Name

Parameters

Returns

Description

AddWith

double value

Func<double, double>

Function to represents addition operation (+) between two values, applying first value as partial application on Add method.

SubtractWith

double value

Func<double, double>

Function to represents subtraction operation (-) between two values, applying first value as partial application on Subtract method.

MultiplyWith

double value

Func<double, double>

Function to represents multiplication operation (*) between two values, applying first value as partial application on Multiply method.

DivideWith

double value

Func<double, double>

Function to represents multiplication operation (/) between two values, applying first value as partial application on Divide method.

Add3With

double value

Func<double, double, double>

Function to represents addition operation (+) between three values, applying first value as partial application on Add3 method.

Add3With

double value

double value2

Func<double, double>

Function to represents addition operation (+) between three values, applying first and second values as partial application on Add3 method.

Subtract3With

double value

Func<double, double, double>

Function to represents subtraction operation (-) between three values, applying first value as partial application on Subtract3 method.

Subtract3With

double value

double value2

Func<double, double>

Function to represents subtraction operation (-) between three values, applying first and second values as partial application on Subtract3 method.

Multiply3With

double value

Func<double, double, double>

Function to represents multiplication operation (*) between three values, applying first value as partial application on Multiply3 method.

Multiply3With

double value

doublevalue2

Func<double, double>

Function to represents multiplication operation (*) between three values, applying first and second values as partial application on Multiply3 method.

Divide3With

double value

Func<double, double, double>

Function to represents division operation (/) between three values, applying first value as partial application on Divide3 method.

Divide3With

double value

double value2

Func<double, double>

Function to represents division operation (/) between three values, applying first and second values as partial application on Divide3 method.

Usage

The properties returns a delegate, so, it's possible to use it as a method.

Add

double value = 10;
double value2 = 5;
double result = DoubleOperations.Add(value, value2);

//result= 15

Subtract

double value = 10;
double value2 = 5;
double result = DoubleOperations.Subtract(value, value2);

//result= 5

Multiply

double value = 10;
double value2 = 5;
double result = DoubleOperations.Multiply(value, value2);

//result= 50

Divide

double value = 10;
double value2 = 5;
double result = DoubleOperations.Divide(value, value2);

//result= 2

For methods you can use a little different sintax. It's necessary because these methods uses the property methods combined with Partial Application.

Because of that, you need to execute the method with the first parameter to creates a new single parameter function that perform the operation.

AddWith

double value = 10;
double value2 = 5;
Func<double, double> addWith= DoubleOperations.AddWith(value);
double result = addWith(value2);

//result= 15

You can also use it as a chainable operation:

double value = 10;
double value2 = 5;
double result = DoubleOperations.AddWith(value)(value2);

//result= 15

The ~With operations are available to the four main operations, all of them follows the same caracteristics that the previous example.

You can use these methods as Partial Applications if you needs to.

Add3With

double value = 10;
double value2 = 5;
double value3 = 5
Func<double, double, double> addWith2= DoubleOperations.Add3With(value);
double result = addWith2(value2, value3);

//result= 20

You can also use it as a chainable operation:

double value = 10;
double value2 = 5;
double value3 = 5
double result = DoubleOperations.Add3With(value)(value2, value3);

//result= 20

You can use the two parameters overload as well:

double value = 10;
double value2 = 5;
double value3 = 5
Func<double, double> addWith= DoubleOperations.Add3With(value, value2);
double result = addWith(value3);

//result= 20
double value = 10;
double value2 = 5;
double value3 = 5
double result = DoubleOperations.Add3With(value,value2)(value3);

//result= 20

Last updated