Class STDef
Class offers the following built-in general purpose functions and constants:
- trigonometric functions;
- mathematical functions;
- string functions;
- other functions
Inheritance
Namespace: GeneralUtils.STDefLib
Assembly: GeneralUtils.STDefLib.dll
Syntax
public static class STDef : Object
Fields
DegToRad
Converts degrees to radians
Declaration
public const double DegToRad = 0.017453292519943295
Field Value
Type | Description |
---|---|
double |
DoublePi
Returns 2*Pi
Declaration
public const double DoublePi = 6.283185307179586
Field Value
Type | Description |
---|---|
double |
HalfPi
Returns Pi/2
Declaration
public const double HalfPi = 1.5707963267948966
Field Value
Type | Description |
---|---|
double |
RadToDeg
Converts radians to degrees
Declaration
public const double RadToDeg = 57.29577951308232
Field Value
Type | Description |
---|---|
double |
TinyZero
Returns 1e-12.
Declaration
public const double TinyZero = 1E-12
Field Value
Type | Description |
---|---|
double |
Zero
Returns 1e-6.
Declaration
public const double Zero = 1E-06
Field Value
Type | Description |
---|---|
double |
Methods
Abs(double)
Returns the absolute value of a specified number
Declaration
public static double Abs(double x)
Parameters
Type | Name | Description |
---|---|---|
double | x | Positive or negative number |
Returns
Type | Description |
---|---|
double | Positive number |
Abs(int)
Returns the absolute value of a specified number
Declaration
public static int Abs(int x)
Parameters
Type | Name | Description |
---|---|---|
int | x | Positive or negative number |
Returns
Type | Description |
---|---|
int | Positive number |
ArcCos(double, AngleUnits)
Returns the angle whose cosine is the specified number (in the specified angle type)
Declaration
public static double ArcCos(double x, AngleUnits units)
Parameters
Type | Name | Description |
---|---|---|
double | x | A number representing a cosine, where "x" must be greater than or equal to -1, but less than or equal to 1 |
AngleUnits | units | Angle units (radians or degrees) |
Returns
Type | Description |
---|---|
double | An angle in the specified angle units |
ArcCos(double)
Returns the angle whose cosine is the specified number
Declaration
public static double ArcCos(double x)
Parameters
Type | Name | Description |
---|---|---|
double | x | A number representing a cosine, where "x" must be greater than or equal to -1, but less than or equal to 1 |
Returns
Type | Description |
---|---|
double | An angle measured in radians |
ArcSin(double, AngleUnits)
Returns the angle whose sine is the specified number (in the specified angle type)
Declaration
public static double ArcSin(double x, AngleUnits units)
Parameters
Type | Name | Description |
---|---|---|
double | x | A number representing a sine, where "x" must be greater than or equal to -1, but less than or equal to 1 |
AngleUnits | units | Angle units (radians or degrees) |
Returns
Type | Description |
---|---|
double | An angle in the specified angle units |
ArcSin(double)
Returns the angle whose sine is the specified number
Declaration
public static double ArcSin(double x)
Parameters
Type | Name | Description |
---|---|---|
double | x | A number representing a sine, where "x" must be greater than or equal to -1, but less than or equal to 1 |
Returns
Type | Description |
---|---|
double | An angle measured in radians |
ArcTan(double, AngleUnits)
Returns the angle whose tangent is the specified number (in the specified angle type)
Declaration
public static double ArcTan(double x, AngleUnits units)
Parameters
Type | Name | Description |
---|---|---|
double | x | A number representing a tangent |
AngleUnits | units | Angle units (radians or degrees) |
Returns
Type | Description |
---|---|
double | An angle in the specified angle units |
ArcTan(double)
Returns the angle whose tangent is the specified number
Declaration
public static double ArcTan(double x)
Parameters
Type | Name | Description |
---|---|---|
double | x | A number representing a tangent |
Returns
Type | Description |
---|---|
double | An angle measured in radians |
ArcTan2(double, double, AngleUnits)
Returns the angle whose tangent is the quotient of two specified numbers (in the specified angle type)
Declaration
public static double ArcTan2(double y, double x, AngleUnits units)
Parameters
Type | Name | Description |
---|---|---|
double | y | The y coordinate of a point |
double | x | The x coordinate of a point |
AngleUnits | units | Angle units (radians or degrees) |
Returns
Type | Description |
---|---|
double | An angle in the specified angle units |
ArcTan2(double, double)
Returns the angle whose tangent is the quotient of two specified numbers
Declaration
public static double ArcTan2(double y, double x)
Parameters
Type | Name | Description |
---|---|---|
double | y | The y coordinate of a point |
double | x | The x coordinate of a point |
Returns
Type | Description |
---|---|
double | An angle measured in radians |
Chr(int)
Converts an integer to a character
Declaration
public static string Chr(int x)
Parameters
Type | Name | Description |
---|---|---|
int | x | A number to be converted |
Returns
Type | Description |
---|---|
string | The character |
Copy(string, int, int)
Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length
Declaration
public static string Copy(string s, int start, int count)
Parameters
Type | Name | Description |
---|---|---|
string | s | Current string |
int | start | The zero-based starting character position of a substring in this instance |
int | count | The number of characters in the substring |
Returns
Type | Description |
---|---|
string | A string that is equivalent to the substring of length length that begins at startIndex in this instance |
Cos(double, AngleUnits)
Returns the cosine of the specified angle (in the specified angle type)
Declaration
public static double Cos(double x, AngleUnits units)
Parameters
Type | Name | Description |
---|---|---|
double | x | An angle value |
AngleUnits | units | Angle units (radians or degrees) |
Returns
Type | Description |
---|---|
double | The cosine of "x" |
Cos(double)
Returns the cosine of the specified angle
Declaration
public static double Cos(double x)
Parameters
Type | Name | Description |
---|---|---|
double | x | An angle, measured in radians |
Returns
Type | Description |
---|---|
double | The cosine of "x" |
IsEqD(double, double, double)
Returns true if d1==d2 with defined tolerance
Declaration
public static bool IsEqD(double d1, double d2, double tolerance)
Parameters
Type | Name | Description |
---|---|---|
double | d1 | |
double | d2 | |
double | tolerance |
Returns
Type | Description |
---|---|
bool |
IsGeD(double, double, double)
Returns true if a more or equal than b with defined tolerance
Declaration
public static bool IsGeD(double a, double b, double Tol = 0)
Parameters
Type | Name | Description |
---|---|---|
double | a | |
double | b | |
double | Tol |
Returns
Type | Description |
---|---|
bool |
IsGtD(double, double, double)
Returns true if a more than b with defined tolerance
Declaration
public static bool IsGtD(double a, double b, double Tol = 0)
Parameters
Type | Name | Description |
---|---|---|
double | a | |
double | b | |
double | Tol |
Returns
Type | Description |
---|---|
bool |
IsLeD(double, double, double)
Returns true if a less or equal than b with defined tolerance
Declaration
public static bool IsLeD(double a, double b, double Tol = 0)
Parameters
Type | Name | Description |
---|---|---|
double | a | |
double | b | |
double | Tol |
Returns
Type | Description |
---|---|
bool |
IsLtD(double, double, double)
Returns true if a less than b with defined tolerance
Declaration
public static bool IsLtD(double a, double b, double Tol = 0)
Parameters
Type | Name | Description |
---|---|---|
double | a | |
double | b | |
double | Tol |
Returns
Type | Description |
---|---|
bool |
IsZeroD(double, double)
Returns true if d==0 with defined tolerance
Declaration
public static bool IsZeroD(double d, double tolerance)
Parameters
Type | Name | Description |
---|---|---|
double | d | |
double | tolerance |
Returns
Type | Description |
---|---|
bool |
Length(string)
Gets the number of characters in the current string
Declaration
public static int Length(string s)
Parameters
Type | Name | Description |
---|---|---|
string | s | Current string |
Returns
Type | Description |
---|---|
int | The number of characters in the current string |
Ord(char)
Converts a character to an integer
Declaration
public static int Ord(char c)
Parameters
Type | Name | Description |
---|---|---|
char | c | A character in char-type to be converted |
Returns
Type | Description |
---|---|
int | Integer value of the character |
Ord(string)
Converts a character to an integer
Declaration
public static int Ord(string s)
Parameters
Type | Name | Description |
---|---|---|
string | s | A character in string-type to be converted |
Returns
Type | Description |
---|---|
int | Integer value of the character. If length of "s" ≠ 1, return value = -1 |
Pos(string, string, int)
Reports the zero-based index of the first occurrence of the specified string in this instance. The search starts at a specified character position
Declaration
public static int Pos(string substring, string s, int start = 0)
Parameters
Type | Name | Description |
---|---|---|
string | substring | The string to seek |
string | s | Current string |
int | start | The search starting position |
Returns
Type | Description |
---|---|
int | The zero-based index position of value from the start of the current instance if that string is found, or -1 if it is not |
Refine(double, double)
Return zero if Abs(d) less that tolerance, otherwise returns d.
Declaration
public static double Refine(double d, double tolerance)
Parameters
Type | Name | Description |
---|---|---|
double | d | A double number to be refined |
double | tolerance | tolerance value |
Returns
Type | Description |
---|---|
double |
Replace(string, string, string)
Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string
Declaration
public static string Replace(string S, string Sub, string newSub)
Parameters
Type | Name | Description |
---|---|---|
string | S | The current string in which to replace |
string | Sub | Old substring to be replaced |
string | newSub | New substring to be replaced with |
Returns
Type | Description |
---|---|
string | A string that is equivalent to the current string except that all instances of "Sub" are replaced with "newSub" |
Round(double, int)
Rounds a double value to a specified number of fractional digits, and rounds midpoint values to the nearest even number
Declaration
public static double Round(double x, int digits)
Parameters
Type | Name | Description |
---|---|---|
double | x | A double number to be rounded |
int | digits | The number of fractional digits in the return value |
Returns
Type | Description |
---|---|
double | The number nearest to value that contains a number of fractional digits equal to "digits" |
Round(double)
Rounds a double value to the nearest integral value, and rounds midpoint values to the nearest even number
Declaration
public static int Round(double x)
Parameters
Type | Name | Description |
---|---|---|
double | x | A double number to be rounded |
Returns
Type | Description |
---|---|
int | The integer nearest "x". |
SameText(string, string)
Compares two strings by ordinal value without case sensitivity
Declaration
public static bool SameText(string s1, string s2)
Parameters
Type | Name | Description |
---|---|---|
string | s1 | First string to compare |
string | s2 | Second string to compare |
Returns
Type | Description |
---|---|
bool | "True" if they are equal; otherwise, "False" |
Sgn(double)
Returns an integer that indicates the sign of a number
Declaration
public static int Sgn(double x)
Parameters
Type | Name | Description |
---|---|---|
double | x | Positive or negative number |
Returns
Type | Description |
---|---|
int | A number that indicates the sign of value (-1, 0, 1) |
Sin(double, AngleUnits)
Returns the sine of the specified angle (in the specified angle type)
Declaration
public static double Sin(double x, AngleUnits units)
Parameters
Type | Name | Description |
---|---|---|
double | x | An angle value |
AngleUnits | units | Angle units (radians or degrees) |
Returns
Type | Description |
---|---|
double | The sine of "x" |
Sin(double)
Returns the sine of the specified angle
Declaration
public static double Sin(double x)
Parameters
Type | Name | Description |
---|---|---|
double | x | An angle, measured in radians |
Returns
Type | Description |
---|---|
double | The sine of "x" |
Sqr(double)
Returns the specified number to the second power
Declaration
public static double Sqr(double x)
Parameters
Type | Name | Description |
---|---|---|
double | x | The number to be raised to a power |
Returns
Type | Description |
---|---|
double | The number raised to the second power |
Sqrt(double)
Returns the square root of a specified number
Declaration
public static double Sqrt(double x)
Parameters
Type | Name | Description |
---|---|---|
double | x | The number whose square root is to be found |
Returns
Type | Description |
---|---|
double | Value of square root |
STFloatToStr(double)
Converts the numeric value of this instance to its equivalent string representation
Declaration
public static string STFloatToStr(double d)
Parameters
Type | Name | Description |
---|---|---|
double | d | Value to be converted |
Returns
Type | Description |
---|---|
string | The string representation of the value |
Str(double, int, int)
Converts the double value of this instance to its equivalent string representation with the additional option of setting a fixed string width
Declaration
public static string Str(double d, int IndRound, int width)
Parameters
Type | Name | Description |
---|---|---|
double | d | Double value to be converted |
int | IndRound | The number of fractional digits |
int | width | Width ensures that the output line is no less than this width, padded with spaces on the left if necessary |
Returns
Type | Description |
---|---|
string | The string representation of the value with the additional option of fixed width and round value |
Str(double)
Converts the numeric value of this instance to its equivalent string representation
Declaration
public static string Str(double d)
Parameters
Type | Name | Description |
---|---|---|
double | d | Double value to be converted |
Returns
Type | Description |
---|---|
string | The string representation of the value |
Str(int, int)
Converts the integer value of this instance to its equivalent string representation with the additional option of setting a fixed string width
Declaration
public static string Str(int n, int width)
Parameters
Type | Name | Description |
---|---|---|
int | n | Integer value to be converted |
int | width | Width ensures that the output line is no less than this width, padded with spaces on the left if necessary |
Returns
Type | Description |
---|---|
string | The string representation of the value with the additional option of fixed width |
Str(int)
Converts the integer value of this instance to its equivalent string representation
Declaration
public static string Str(int n)
Parameters
Type | Name | Description |
---|---|---|
int | n | Integer value to be converted |
Returns
Type | Description |
---|---|
string | The string representation of the value |
StringOfChar(char, int)
Generates a sequence of strings containing one duplicate value
Declaration
public static string StringOfChar(char c, int repeatCount)
Parameters
Type | Name | Description |
---|---|---|
char | c | The value to duplicate the specified number of times |
int | repeatCount | Number of duplicates |
Returns
Type | Description |
---|---|
string | A string containing all duplicates in the specified quantity. Empty string if repeatCount less than 1. |
STTryStrToFloat(string, out double)
Converts the string representation of a number to its float equivalent. A return value indicates whether the conversion succeeded
Declaration
public static bool STTryStrToFloat(string s, out double d)
Parameters
Type | Name | Description |
---|---|---|
string | s | A string containing a number to convert |
double | d | When this method returns, contains the float value equivalent of the number contained in "s" |
Returns
Type | Description |
---|---|
bool | "True" if "s" was converted successfully; otherwise, "false". |
Tan(double, AngleUnits)
Returns the tangent of the specified angle (in the specified angle type)
Declaration
public static double Tan(double x, AngleUnits units)
Parameters
Type | Name | Description |
---|---|---|
double | x | An angle value |
AngleUnits | units | Angle units (radians or degrees) |
Returns
Type | Description |
---|---|
double | The tangent of "x" |
Tan(double)
Returns the tangent of the specified angle
Declaration
public static double Tan(double x)
Parameters
Type | Name | Description |
---|---|---|
double | x | An angle, measured in radians |
Returns
Type | Description |
---|---|
double | The tangent of "x" |
Trunc(double)
Truncates a double-type value to an integer-type value
Declaration
public static int Trunc(double x)
Parameters
Type | Name | Description |
---|---|---|
double | x | A double number to be truncated |
Returns
Type | Description |
---|---|
int | Integer value that is the value of "x" rounded toward zero |
TryStrToInt(string, out int)
Converts the string representation of a number to its integer equivalent. A return value indicates whether the conversion succeeded
Declaration
public static bool TryStrToInt(string s, out int i)
Parameters
Type | Name | Description |
---|---|---|
string | s | A string containing a number to convert |
int | i | When this method returns, contains the integer value equivalent of the number contained in "s" |
Returns
Type | Description |
---|---|
bool | "True" if "s" was converted successfully; otherwise, "false". |