# Math Functions

Last updated Sunday, November 18, 2001.

# General functions

## Absolute value

Given a number value, an absolute value function returns the positive value of value. For example, given the value -15, it returns 15.

#### C / C++

TODO: Fill this in.

#### Abs function

using System.Math;

Abs(value)

#### Java

TODO: Fill this in.

#### abs function

abs(value)

The type of the return value is the same as the argument (int or float).

#### fabs function

from math import fabs

fabs(value)

Like the abs function, except that the return type is always a float.

abs(value)

VB 6 abs(value)

#### Abs function

imports System.Math

Abs(value)

## Ceiling

#### C / C++

TODO: Fill this in.

#### Ceiling static method

using System.Math;

Ceiling(value)

This function returns a double.

According to the MSDN documentation, "the behavior of this method follows IEEE Standard 754, section 4."

#### Java

TODO: Fill this in.

#### ceil function

from math import ceil

ceil(value)

Returns a float containing value rounded up to the nearest integer.

#### ceil function

ceil(value as Double)

Returns a double containing value rounded up to the nearest integer.

#### Use custom function: ceil

VB 6 doesn't have a built-in ceiling function. Use the code below:

public function Ceil(value as double)

Ceil = CDbl(CLng(value + 0.5))

end function

This code takes advantage of the fact that CLng rounds to the nearest decimal. To force it to always round up, .5 is added to its argument. Since this implementation of the ceiling function uses a function that converts value to a long, it will only work for values between -2,147,483,648 and 2,147,483,647 (the range of numbers that can be handled by a long).

VB .NET

#### Ceiling shared method

imports System.Math

Ceiling(value)

This function returns a double.

According to the MSDN documentation, "the behavior of this method follows IEEE Standard 754, section 4."

## e raised to a power

#### C / C++

TODO: Fill this in.

#### Exp static method

using System.Math;

Exp(value)

This function returns a double.

#### Java

TODO: Fill this in.

#### exp function

from math import exp

exp(value)

This function returns a float.

#### exp function

exp(value as Double)

This function returns a double.

#### exp function

exp(value as number)

This function returns a double.
VB .NET

#### Exp shared method

imports System.Math

Exp(value)

This function returns a double.

## Exponentiation

#### C / C++

TODO: Fill this in.

#### Pow static method

using System.Math;

Pow(base, power)

This function returns a double.

#### Java

TODO: Fill this in.

#### ** operator

base ** power

Returns base raised to the powerth power. The result is an int if both base and power are ints, otherwise the result is a float.

#### pow function

from math import pow

pow(base, power)

Returns a float containing base raised to the powerth power.

#### Pow function

Pow(base as Double, power as Double)

Returns a double containing base raised to the powerth power.

#### ^ operator

base ^ power

Returns a double containing base raised to the powerth power.

The ^ operator is more in line with "traditional" versions of BASIC than RB’s Pow function.

#### Pow shared method

imports System.Math

Pow(base, power)

This function returns a double.

## Floor

#### C / C++

TODO: Fill this in.

#### Floor static method

using System.Math;

Floor(value)

This function returns a double.

According to the MSDN documentation, "the behavior of this method follows IEEE Standard 754, section 4."

#### Java

TODO: Fill this in.

#### floor function

from math import floor

floor(value)

Returns a float containing value rounded down to the nearest integer.

#### floor function

floor(value as Double)

Returns a double containing value rounded down to the nearest integer.

#### Use custom function: floor

VB 6 doesn't have a built-in ceiling function. Use the code below:

public function Floor(value as double)

Floor = CDbl(CLng(value - 0.5))

end function

This code takes advantage of the fact that CLng rounds to the nearest decimal. To force it to always round down, .5 is subtracted from its argument. Since this implementation of the ceiling function uses a function that converts value to a long, it will only work for values between -2,147,483,648 and 2,147,483,647 (the range of numbers that can be handled by a long).

VB .NET

#### Floor shared method

imports System.Math

Floor(value)

This function returns a double.

According to the MSDN documentation, "the behavior of this method follows IEEE Standard 754, section 4."

## Fractional and integer parts of a number

#### C / C++

TODO: Fill this in.

#### C#

TODO: Fill this in.

#### Java

TODO: Fill this in.

#### Python

from math import modf

modf(value)

Returns a 2-tuple of floats containing the fractional and integer parts of value, in that order.

#### RB

TODO: Fill this in.

#### VB

TODO: Fill this in.

## Hypotenuse, length of

#### C / C++

TODO: Fill this in.

#### C#

TODO: Fill this in.

#### Java

TODO: Fill this in.

#### Python

from math import hypot

hypot(x, y)

Returns a float containing the length of the hypotenuse of a right-angled triangle having width x and height y.

#### RB

TODO: Fill this in.

#### VB

TODO: Fill this in.

## Logarithm

#### C / C++

TODO: Fill this in.

#### Log static method, base e

using System.Math;

Log(value)

This function returns a double.

#### Log10 static method

using System.Math;

Log10(value)

This function returns a double containing the base 10 logarithm of value.

#### Log static method, any base

using System.Math;

Log(value, base)

This function returns a double containing the logarithm of value in the given base.

#### Java

TODO: Fill this in.

#### log function

from math import log

log(value)

Returns a float containing the natural logarithm (base e) of value.

#### log10 function

from math import log10

log10(value)

Returns a float containing the base 10 logarithm of value.

#### log function

log(value as Double)

Returns a double containing the natural logarithm (base e) of value.

#### log function

Log(value as number)

Returns a double containing the natural logarithm (base e) of value.

#### Log shared method, base e

imports System.Math

Log(value)

This function returns a double.

#### Log10 shared method

imports System.Math

Log10(value)

This function returns a double containing the base 10 logarithm of value.

#### Log shared method, any base

imports System.Math

Log(value, base)

This function returns a double containing the logarithm of value in the given base.

### Notes

The base of the logarithm functions in most programming is the transcendental number e (approximate value 2.718282) -- what both they refer to as Log(x), math people would call "ln(x)" (and is often pronounced "lawn of x").

A logarithm is simply the inverse of exponentiation, just as subtraction is the inverse of addition. As exponentiation answers the question "What is the value of the nth power of x?", logarithms answer the question "What power of x gets me y?" For example, the base 5 logarithm of 625 is 4 (because 5 raised to the 4th power is 625), and the base 25 logarithm of 625 is 2 (since 25 squared is 625).

"But wait," you say, "I'm stuck with base e logarithms!" That's okay, because you can calculate the base n logarithm for any number x by using this formula: Logn(x) = Log(x) / Log(n). Suppose you wanted to knew that the number 65,536 is a power 2, but didn't know which power of 2. You'd simply use the formula Log(65536)/Log(2) to get 16, which is correct, since 2 to the 16th power is 65,536.

Logarithms used to be an indispensable calculating aid before the days of adding machines. People used to publish tables of logarithms of numbers to make calculation easier (slide rules are essentially mechanized logarithm tables). I won't go into the details of why it's so, but rather than multiply two very large numbers xand y to get z (which is tedious and error-prone), it's much easier to add log(x) and log(y) to get log(z) and then see what number corresponds to log(z) in a table.

Logarithms are used to make dealing with extremely big numbers or wide ranges of numbers easier since small logarithms are associated with big numbers. The Richter scale for measuring the intensity of earthquakes is a base-10 logarithmic scale; for example an earthquake that is rated 6 is ten times as powerful as one that rated 5 and 100 times as powerful as one that rated 4.

## Max

#### C / C++

TODO: Fill this in.

#### Max static method

using System.Math;

Max(value1, value2)

value1 and value2 must be of the same type. This function returns a value of the same type as value1 and value2.

#### Java

TODO: Fill this in.

#### max function

max(value1, value2, value3, ... , valueN)

The type of the returned value is the type of the largest value.

#### max function

max(number1 as Double, number2 as Double)

This function returns a double.

#### Use custom function: Max

VB 6 doesn't have a built-in max function. Use the code below:

Function Max(value1 as Double, value2 as Double) as Double

if (value1 > value2 2) then
Max = value1

else

Max = value2

end if

End Function

This function is modelled to be equivalent to RB's Max function.

VB 6 does have a function called Max, but it’s used to find the largest value of a database field and not for comparing two numbers.

VB .NET

#### Max shared method

imports System.Math

Max(value1, value2)

value1 and value2 must be of the same type. This function returns a value of the same type as value1 and value2.

## Min

#### C / C++

TODO: Fill this in.

#### Min static method

using System.Math;

Min(value1, value2)

value1 and value2 must be of the same type. This function returns a value of the same type as value1 and value2.

#### Java

TODO: Fill this in.

#### min function

min(value1, value2, value3, ... , valueN)

The type of the returned value is the type of the smallest value.

#### min function

Min(number1 as Double, number2 as Double)

This function returns a double.

#### Use custom function: Min

VB 6 doesn't have a built-in min function. Use the code below:

Function Min(value1 as Double, value2 as Double) as Double

if (value1 < value2 2) then
Min = value1

else

Min = value2

end if

End Function

This function is modelled to be equivalent to RB's Min function.

VB 6 does have a function called Min, but it’s used to find the smallest value of a database field and not for comparing two numbers.

VB .NET

#### Min shared method

imports System.Math

Min(value1, value2)

value1 and value2 must be of the same type. This function returns a value of the same type as value1 and value2.

## Random number generator

#### C / C++

TODO: Fill this in.

#### Random class

The .NET library provides the Random class for generating random numbers.

The Random class provides two constructors:

• Random(), which creates an instance of the class using a seed value based on the current time.
• Random(seed), which creates an instance of the class using the integer seed as the seed value.

A random number generator uses its seed value to generate a sequence of pseudo-random numbers. Typically, when you want a new random number, the random number generator provides the next number in that sequence. This is why the Random class' methods for getting random numbers all begin with "Next".

#### Next method

The Next method returns a random integer. There are three variations:

• myRandom.Next(), which returns a positive integer in the range from 0 to 2,147,483,646 (one less than the largest number that can be held by type int32)
• myRandom.Next(value), which returns a positive integer in the range from 0 to the (value - 1). value must be an integer greater than or equal to zero.
• myRandom.Next(lowValue, highValue), which returns a positive integer in the range from lowValue to (highValue - 1). lowValue and highValue must be integers and highValue must be greater than or equal to lowValue.

#### NextDouble method

myRandom.NextDouble()

This method returns a random double between 0.0 and 1.0. This method is similar to many other prgramming languages' random number functions.

#### NextBytes method

myRandom.NextBytes(myByteArray)

This method fills a given array of bytes with random values.

#### Java

TODO: Fill this in.

#### Python

TODO: Fill this in.

#### Rnd function

Rnd

Returns a double containing a random number between 0 and 1 with seven decimal places.

Rnd([value])

#### Randomize function

Randomize([seed])

Returns a double containing a random number between 0 and 1 with seven decimal places.

• In VB, Rnd can take an optional argument, which determines the kind of random numbers returned:
• if number < 0: same number every time, using number as the seed value
• if number > 0: next random number in the sequence
• if number = 0: the most recently generated number
• no value provided: next random number in the sequence

VB has the Randomize statement, which re-seeds the random number generator using seed as a value for "seeding" the generator if seed is provided, or the system timer if seed is not provided.

#### Random class

The .NET library provides the Random class for generating random numbers.

The Random class provides two constructors:

• Random(), which creates an instance of the class using a seed value based on the current time.
• Random(seed), which creates an instance of the class using the integer seed as the seed value.

A random number generator uses its seed value to generate a sequence of pseudo-random numbers. Typically, when you want a new random number, the random number generator provides the next number in that sequence. This is why the Random class' methods for getting random numbers all begin with "Next".

#### Next method

The Next method returns a random integer. There are three variations:

• myRandom.Next(), which returns a positive integer in the range from 0 to 2,147,483,646 (one less than the largest number that can be held by type int32)
• myRandom.Next(value), which returns a positive integer in the range from 0 to the (value - 1). value must be an integer greater than or equal to zero.
• myRandom.Next(lowValue, highValue), which returns a positive integer in the range from lowValue to (highValue - 1). lowValue and highValue must be integers and highValue must be greater than or equal to lowValue.

#### NextDouble method

myRandom.NextDouble()

This method returns a random double between 0.0 and 1.0. This method is similar to many other prgramming languages' random number functions.

#### NextBytes method

myRandom.NextBytes(myByteArray)

This method fills a given array of bytes with random values.

## Rounding function

#### C / C++

TODO: Fill this in.

#### Round static method, round to nearest integer

using System.Math;

Round(value)

value must be either a Decimal or a double. This function returns a value of the same type as value.

#### Round static method, round with specified precision

using System.Math;

Round(value, numberOfDecimals)

value must be either a Decimal or a double; numberOfDecimals must be an int. This function returns value rounded to numberOfDecimals decimal places; the return value is of the same type as value.

#### Java

TODO: Fill this in.

#### Python

round(value[, decimal places])

#### RB

Round(value as Double)

Returns a double: value rounded to the nearest whole number.

#### VB 6

CInt(value as number or String)

CLng(value as number or String)

The CInt and CLng functions perform rounding, but also return integer and long values, respectively. To get a double result like RB's Round, use CDbl to convert the integer or long into a double.

VB .NET

#### Round shared method, round to nearest integer

imports System.Math

Round(value)

value must be either a Decimal or a double. This function returns a value of the same type as value.

#### Round shared method, round with specified precision

imports System.Math

Round(value, numberOfDecimals)

value must be either a Decimal or a double; numberOfDecimals must be an int. This function returns value rounded to numberOfDecimals decimal places; the return value is of the same type as value.

## Sign of a number

#### C / C++

TODO: Fill this in.

#### Sign static method

using System.Math;

Sign(value)

This function returns a value of the same type as value.

#### Java

TODO: Fill this in.

#### Use custom function: sign

Python has no built-in sign function, nor is it in the math module. Use the code below:

def Sign(value):

if value > 0:
return 1

elif value < 0:
return -1

else:
return 0

#### Use custom function: sign

RB has no built-in sign function. Use the code below:

Function Sign(value as double) as integer

if value > 0 then
return 1

elseif value < 0 then
return -1

else
return 0

end if

End Function

#### Sgn function

Sgn(value)

Returns a number indicating the sign of the given number.

 if value is Sgn returns greater than zero 1 zero 0 less than zero -1

#### Sign shared method

imports System.Math

Sign(value)

This function returns a value of the same type as value.

VB and VBA in a Nutshell has this to say about the Sgn function: "I suppose that someone, somewhere has found a really good use for the Sgn function. However, its usefulness escapes me..." (p. 518).

The Sgn function goes back to the days of BASIC (as opposed to present-day Basic). It has some use in the construction of certain hyperbolic trig formulas (see entry), but aside from that, it doesn't seem terribly useful.

## String, value of

#### C / C++

TODO: Fill this in.

#### Java

TODO: Fill this in.

#### Python

TODO: Fill this in.

#### RB

Val(string)

CDbl(string)

Returns a double containing the numeric form of the string number. Val stops reading the string after the first character that isn’t recognized as part of a number. For example, Val("123 Springfield Lane") evaluates as 123.0.

Val recognizes the prefixes for hexadecimal (&H) and octal(&O) - it will convert these strings into their decimal equivalent.

#### VB

Val(string)

CByte(expression)

CCur(expression)

CDbl(expression)

CDec(expression)

CInt(expression)

CLng(expression)

CSng(expression)

Val returns a double containing the numeric form of the string number. Val stops reading the string after the first character that isn’t recognized as part of a number. For example, Val("123 Springfield Lane") evaluates as 123.0.

## Square root

#### C / C++

TODO: Fill this in.

#### Sqrt static method

using System.Math;

Sqrt(value)

This function expects a double and returns a double.

#### Java

TODO: Fill this in.

#### sqrt function

from math import sqrt

sqrt(value)

This function returns a float.

#### Sqrt function

Sqrt(value as Double)

This function returns a double.

#### Sqr function

Sqr(value as number)

This function returns a double.

VB .NET

#### Sqrt shared method

imports System.Math

Sqrt(value)

This function expects a double and returns a double.

# Boolean functions

## And, bitwise

value1 & value2

value1 & value2

#### RB

BitwiseAnd(value1 as Integer, value2 as Integer)

Returns a double containing the decimal value equivalent to the result of a bitwise AND operation on the binary values of value1 and value2.

#### VB

value1 And value2

Returns a decimal value equivalent to the result of a bitwise AND operation on the binary values of value1 and value2. value1 and value2 can be any valid numeric expression. If either value1 or value2 contain a fractional part, they are first rounded to the nearest whole number and then the And operation is performed.

### Truth table

The chart below shows the results of a bitwise And operation for each bit in value1 and value2.

 if a bit in value1 is and the corresponding bit in value2 is then the corresponding bit in the result is 0 0 0 0 1 0 1 0 0 1 1 1

## And, logical

expr1 && expr2

expr1 and expr2

#### RB

expr1 and expr2

This operator returns True if and only if expr1 and expr2 are both True, otherwise it returns False. expr1 and expr2 can be any valid boolean expression.

#### VB

expr1 and expr2

This operator returns True if and only if expr1 and expr2 are both True, otherwise it returns False. expr1 and expr2 can be any valid boolean expression.

### Truth table

The chart below shows the results of a logical And operation for expr1 and expr2.

 if expr1 evaluates as and expr2 evaluates as then the result is false false false false true false true false false true true true

## Equivalence, bitwise

### Visual Basic 5.0 / 6.0

value1 Eqv value2

Returns a decimal value equivalent to the result of a bitwise equivalence operation on the binary values of number1 and number2. number1 and number2 can be any valid numeric expression.

No equivalent.

### Usage Notes

The chart below shows the results of a bitwise Equivalence operation for each bit in value1 and value2.

 if a bit in value1 is and the corresponding bit in value2 is then the corresponding bit in the result is false false true false true false true false false true true true

## Equivalence, logical

### Visual Basic 5.0 / 6.0

number1 Eqv number2

Returns a decimal value equivalent to the result of a bitwise equivalence operation on the binary values of number1 and number2. number1 and number2 can be any valid numeric expression.

### REALBasic 1.0 / 2.0

No equivalent.

The code for a function that emulates VB's Eqv function appears below.

Function VBEqv(expr1 as boolean, expr2 as boolean) as boolean

return (expr1 = expr2)

End Function

### Usage Notes

The chart below shows the results of a logical Equivalence operation for expr1 and expr2.

 if expression1 evaluates as and expression2 evaluates as then the result is false false true false true false true false false true true true

## Exclusive or, bitwise

expr1 ^ expr2

expr1 ^ expr2

#### RB

expr1 bitwiseXor expr2

Returns a double containing the decimal value equivalent to the result of a bitwise exclusive OR operation on the binary values of value1 and value2.

#### VB

expr1 xor expr2

Returns a decimal value equivalent to the result of a bitwise exclusive OR operation on the binary values of number1 and number2. number1 and number2 can be any valid numeric expression.

 if a bit in value1 is and the corresponding bit in value2 is then the corresponding bit in the result is 0 0 0 0 1 1 1 0 1 1 1 0

## Exclusive or, logical

expr1 ^^ expr2

#### Python

TODO: Fill this in.

#### RB

No equivalent.

Use the following function to emulate an Exclusive Or:

Function VBXor(expr1 as boolean, expr2 as boolean) as boolean

return (expr1 or expr2) and (not (expr1 and expr2))

End Function

#### VB

expr1 Xor expr2

This operator returns True if either expr1 and expr2 -- but not both -- are True, otherwise it returns False. expr1 and expr2 can be any valid boolean expression.

### Usage Notes

The chart below shows the results of a logical Exclusive Or operation for expr1 and expr2.

 if expression1 evaluates as and expression2 evaluates as then the result is false false false false true true true false true true true false

## Implication, bitwise

#### C-based languages

TODO: Fill this in.

#### Python

TODO: Fill this in.

#### RB

TODO: Fill this in.

#### VB

number1 Imp number2

Returns a decimal value equivalent to the result of a bitwise implication operation on the binary values of number1 and number2. number1 and number2 can be any valid numeric expression.

 if a bit in value1 is and the corresponding bit in value2 is then the corresponding bit in the result is 0 0 1 0 1 1 1 0 0 1 1 1

## Implication, logical

#### C-based languages

TODO: Fill this in.

#### Python

TODO: Fill this in.

#### RB

No equivalent.

The implication function below emulates a good portion of VB's Imp function. There is no specially-defined Null value in RB, so the RB implication function below deals only with true and false values.

Function VBImp(expr1 as boolean, expr2 as boolean) as boolean

if ((expr1) and (not expr2))

return false

else

return true

end if

End Function

#### VB

number1 Imp number2

Returns a decimal value equivalent to the result of a bitwise implication operation on the binary values of number1 and number2. number1 and number2 can be any valid numeric expression.

 if expression1 evaluates as and expression2 evaluates as then the result is false false true false true true true false false true true true Null Null Null Null false Null Null true true false Null true true Null Null

Usage Notes

 if expression1 evaluates as and expression2 evaluates as then the result is false false true false true true true false false true true true

## Negation, bitwise

!expr

#### Python

TODO: Fill this in.

#### RB

TODO: Fill this in.

#### VB

Not arg

Returns a decimal value equivalent to the result of a bitwise negation on the binary value arg. arg can be any valid numeric expression.

 if a bit in arg is and the corresponding bit in the result is 0 1 1 0

## Negation, logical

!expr

#### Python

TODO: Fill this in.

#### RB

Not expr

This operator returns True if either expr is False and returns False when expr is True. expr can be any valid boolean expression.

#### VB

Not expr

This operator returns True if either expr is False and returns False when expr is True. expr can be any valid boolean expression.

### Usage Notes

 if expr is the result is false true true false

## Or, bitwise

value1 | value2

value1 | value2

#### RB

BitwiseOr(value1 as Integer, value2 as Integer)

Returns a decimal value equivalent to the result of a bitwise Exlusive Or operation on the binary values of value1 and value2.

#### VB

value1 Or value2

Returns a decimal value equivalent to the result of a bitwise Exlusive Or operation on the binary values of value1 and value2. value1 and value2 can be any valid numeric expression.

## Usage Notes

 if a bit in value1 is and the corresponding bit in value2 is then the corresponding bit in the result is 0 0 0 0 1 1 1 0 1 1 1 1

## Or, logical

expr1 || expr2

#### Python

expr1 or expr2

This operator returns True if either expr1 and expr2 (or both) are True, otherwise it returns False. expr1 and expr2 can be any valid boolean expression.

#### RB

expr1 or expr2

This operator returns True if either expr1 and expr2 (or both) are True, otherwise it returns False. expr1 and expr2 can be any valid boolean expression.

#### VB

expr1 or expr2

This operator returns True if either expr1 and expr2 (or both) are True, otherwise it returns False. expr1 and expr2 can be any valid boolean expression.

## Usage Notes

The chart below shows the results of a logical Or operation for expr1 and expr2.

 if expr1 evaluates as and expr2 evaluates as then the result is false false false false true true true false true true true true

# Trigonometric functions

## Arccosine, a.k.a. inverse cosine

#### C / C++

TODO: Fill this in.

#### Acos function

using System.Math;

Acos(value)

This function returns a double.

#### Java

TODO: Fill this in.

#### acos function

from math import acos

acos(cosine)

This function returns a float.

#### acos function

acos(cosine)

This function returns a double.

#### Use custom function: acos

VB 6 has no built-in arccosine function. Use the function below:

public function acos(value) as double

acos = atn(-value / sqr(-value * value + 1)) + 2 * atn(1)

end function

#### Acos shared method

imports System.Math

Acos(value)

This function returns a double.

## Arcsine, a.k.a. inverse sine

#### C / C++

TODO: Fill this in.

#### Asin static method

using System.Math;

Asin(value)

This function returns a double.

#### Java

TODO: Fill this in.

#### asin function

from math import asin

asin(sine)

This function returns a float.

#### asin function

asin(sine as Double)

This function returns a double.

#### VB

No equivalent.

You have to roll your own:

asin(sine) = atn(sine / sqr(-sine * sine + 1)

VB .NET

#### Asin shared method

imports System.Math

Asin(value)

This function returns a double.

## Arctangent, a.k.a. inverse tangent

#### C / C++

TODO: Fill this in.

#### Atan static method

using System.Math;

Atan(value)

This function returns a double.

#### Atan2 static method

using System.Math;

Atan2(y, x)

Returns a double containing the angle between the positive x-axis and the point at coordinates (x, y).

#### Java

TODO: Fill this in.

#### atan function

from math import atan

atan(tangent)

Returns a float containing the angle of the given tangent, expressed in radians.

#### atan2 function

from math import atan2

atan2(y, x)

Returns a float containing the angle between the positive x-axis and the point at coordinates (x, y).

#### atan function

atan(tangent as Double)

This function returns a double.

#### atn function

atn(tangent as number)

This function returns a double.

VB .NET

#### Atan shared method

imports System.Math

Atan(value)

This function returns a double.

#### Atan2 shared method

imports System.Math

Atan2(y, x)

Returns a double containing the angle between the positive x-axis and the point at coordinates (x, y).

## Cosine

#### C / C++

TODO: Fill this in.

#### Cos static method

using System.Math;

Cos(value)

This function returns a double.

#### Java

TODO: Fill this in.

#### cos function

from math import cos

cos(angle)

This function returns a float.

#### cos function

cos(angle as Double)

This function returns a double.

#### cos function

cos(angle as number)

This function returns a double.

VB .NET

#### Cos shared method

imports System.Math

Cos(value)

This function returns a double.

## Hyperbolic trigonometric functions

### VB 5.0 / 6.0

Hyperbolic functions are not built into VB, but can be created using the formulas below.

##### Inverse hyperbolic sine

Arcsinh(x) = Log(x + Sqr(x * x + 1))

##### Inverse hyperbolic cosine

Arccosh(x) = Log(x + Sqr(x * x - 1))

##### Inverse hyperbolic tangent

Arctanh(x) = Log((1 + x) / (1 - x)) / 2

##### Inverse hyperbolic secant

Arcsech(x) = Log(Sqr(-x * x + 1) + 1) / x)

##### Inverse hyperbolic cosecant

Arccsch(x) = Log((Sgn(x) * Sqr(x * x + 1) + 1) / x)

##### Inverse hyperbolic cotangent

Arccoth(x) = Log((x + 1) / (x - 1)) / 2

These formulas came from VB and VBA in a Nutshell (p. 419).

### RB 1.0 / 1.1

Hyperbolic functions are not built into RB, but can be built using the formulas above. Note that the Sgn function does not exist in REALBasic; you can create it (see the entry for "Sign fo a number" on this page). Also note that what VB calls Sqr, RB calls Sqrt.

## Sine

#### C / C++

TODO: Fill this in.

#### Sin static method

using System.Math;

Sin(value)

This function returns a double.

#### Java

TODO: Fill this in.

#### sin function

from math import sin

sin(angle)

This function returns a float.

#### sin function

sin(angle as Double)

This function returns a double.

#### sin function

sin(angle as number)

This function returns a double.

VB .NET

#### Sin shared method

imports System.Math

Sin(value)

This function returns a double.

## Tangent

#### C / C++

TODO: Fill this in.

#### Tan static method

using System.Math;

Abs(value)

This function returns a double.

#### Java

TODO: Fill this in.

#### tan function

from math import tan

tan(angle)

This function returns a float.

#### tan function

tan(angle)

This function returns a double.

#### tan function

tan(angle)

This function returns a double.

VB .NET

#### Tan shared method

imports System.Math

Abs(value)

This function returns a double.