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.

C#

Abs function

using System.Math;

Abs(value)

Java

TODO: Fill this in.

Python

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.

RB

abs(value)

VB 6 abs(value)

VB .NET

Abs function

imports System.Math

Abs(value)

Ceiling

C / C++

TODO: Fill this in.

C#

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.

Python

ceil function

from math import ceil

ceil(value)

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

RB

ceil function

ceil(value as Double)

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

VB 6

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.

C#

Exp static method

using System.Math;

Exp(value)

This function returns a double.

Java

TODO: Fill this in.

Python

exp function

from math import exp

exp(value)

This function returns a float.

RB

exp function

exp(value as Double)

This function returns a double.

VB 6

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.

C#

Pow static method

using System.Math;

Pow(base, power)

This function returns a double.

Java

TODO: Fill this in.

Python

** 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.

RB

Pow function

Pow(base as Double, power as Double)

Returns a double containing base raised to the powerth power.

VB 6

^ 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.

VB .NET

Pow shared method

imports System.Math

Pow(base, power)

This function returns a double.

Floor

C / C++

TODO: Fill this in.

C#

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.

Python

floor function

from math import floor

floor(value)

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

RB

floor function

floor(value as Double)

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

VB 6

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.

C#

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.

Python

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.

RB

log function

log(value as Double)

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

VB 6

log function

Log(value as number)

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

VB .NET

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.

C#

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.

Python

max function

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

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

RB

max function

max(number1 as Double, number2 as Double)

This function returns a double.

VB 6

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.

C#

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.

Python

min function

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

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

RB

min function

Min(number1 as Double, number2 as Double)

This function returns a double.

VB 6

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.

C#

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.

RB

Rnd function

Rnd

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

VB

Rnd function

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.

VB .NET

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.

C#

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.

C#

Sign static method

using System.Math;

Sign(value)

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

Java

TODO: Fill this in.

Python

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

RB

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

VB 6

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

VB .NET

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.

C#

 

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.

C#

Sqrt static method

using System.Math;

Sqrt(value)

This function expects a double and returns a double.

Java

TODO: Fill this in.

Python

sqrt function

from math import sqrt

sqrt(value)

This function returns a float.

RB

Sqrt function

Sqrt(value as Double)

This function returns a double.

VB 6

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

C-based languages

value1 & value2

Python

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

C-based languages

expr1 && expr2

Python

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.

REALBasic 1.0 / 2.0

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

C-based languages

expr1 ^ expr2

Python

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

C-based languages

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

C-based languages

!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

C-based languages

!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

C-based languages

value1 | value2

Python

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

C-based languages

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.

C#

Acos function

using System.Math;

Acos(value)

This function returns a double.

Java

TODO: Fill this in.

Python

acos function

from math import acos

acos(cosine)

This function returns a float.

RB

acos function

acos(cosine)

This function returns a double.

VB 6

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

VB .NET

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.

C#

Asin static method

using System.Math;

Asin(value)

This function returns a double.

Java

TODO: Fill this in.

Python

asin function

from math import asin

asin(sine)

This function returns a float.

RB

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.

C#

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.

Python

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).

RB

atan function

atan(tangent as Double)

This function returns a double.

VB

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.

C#

Cos static method

using System.Math;

Cos(value)

This function returns a double.

Java

TODO: Fill this in.

Python

cos function

from math import cos

cos(angle)

This function returns a float.

RB

cos function

cos(angle as Double)

This function returns a double.

VB

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.

C#

Sin static method

using System.Math;

Sin(value)

This function returns a double.

Java

TODO: Fill this in.

Python

sin function

from math import sin

sin(angle)

This function returns a float.

RB

sin function

sin(angle as Double)

This function returns a double.

VB

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.

C#

Tan static method

using System.Math;

Abs(value)

This function returns a double.

Java

TODO: Fill this in.

Python

tan function

from math import tan

tan(angle)

This function returns a float.

RB

tan function

tan(angle)

This function returns a double.

VB

tan function

tan(angle)

This function returns a double.

VB .NET

Tan shared method

imports System.Math

Abs(value)

This function returns a double.