Announcements
Hi
Is it possible to calculate the following in AL:
Example calculation formulas:
4^2 = 16 [4 high 2]
64^(1/3) = 4 [3. Root 64]
sqrt(25) = 5 [root 25]
sin(1/2) = 0.479 [sinus 1/2]
cos(1) = 0.540 [cosine1]
tan(1/2) = 0.546 [tangens 1/2]
cotan(1/2) = 1,830 [cotangens]
fac(4) = 24 [faculty 4 (1*2*3*4)]
ceil(5/2) = 3 [round up to integer)
floor(5/2) = 2 [round to integer]
abs(7-10) = 3 [Removing sign]
pi *2 = 6,283 [circle number Pi * 2]
Thank U!
Hi, you can check codeunit 710 Math.
// ------------------------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. // ------------------------------------------------------------------------------------------------ ////// Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions. /// codeunit 710 Math { Access = Public; var DotNetMath: DotNet Math; ////// Returns the value of pi. /// /// Value of pi. procedure Pi(): Decimal begin exit(3.1415926535897931); end; ////// Returns the value of E. /// /// Value of E. procedure E(): Decimal begin exit(2.7182818284590451); end; ////// Returns the absolute value of a Decimal number. /// /// A decimal. /// A decimal number, x, such that 0 ≤ x ≤MaxValue procedure Abs(decimalValue: Decimal): Decimal begin exit(DotNetMath.Abs(decimalValue)); end; ////// Returns the angle whose cosine is the specified number. /// /// A number representing a cosine. /// An angle, θ, measured in radians, such that 0 ≤θ≤π procedure Acos(decimalValue: Decimal): Decimal begin exit(DotNetMath.Acos(decimalValue)); end; ////// Returns the angle whose sine is the specified number. /// /// A number representing a sine, where decimalValue must be greater than or equal to -1, but less than or equal to 1. /// An angle, θ, measured in radians, such that -π/2 ≤θ≤π/2 procedure Asin(decimalValue: Decimal): Decimal begin exit(DotNetMath.Asin(decimalValue)); end; ////// Returns the angle whose tangent is the specified number. /// /// A number representing a tangent. /// An angle, θ, measured in radians, such that -π/2 ≤θ≤π/2. procedure Atan(decimalValue: Decimal): Decimal begin exit(DotNetMath.Atan(decimalValue)); end; ////// Returns the angle whose tangent is the quotient of two specified numbers. /// /// The y coordinate of a point. /// The x coordinate of a point. /// An angle, θ, measured in radians, such that -π≤θ≤π, and tan(θ) = y / x, where (x, y) is a point in the Cartesian plane. procedure Atan2(y: Decimal; x: Decimal): Decimal begin exit(DotNetMath.Atan2(y, x)); end; ////// Produces the full product of two 32-bit numbers. /// /// The first number to multiply. /// The second number to multiply. /// The number containing the product of the specified numbers. procedure BigMul(a: Integer; b: Integer): BigInteger begin exit(DotNetMath.BigMul(a, b)); end; ////// Returns the smallest integral value that is greater than or equal to the specified decimal number. /// /// A decimal number. /// The smallest integral value that is greater than or equal to decimalValue. procedure Ceiling(decimalValue: Decimal): Decimal begin exit(DotNetMath.Ceiling(decimalValue)); end; ////// Returns the cosine of the specified angle. /// /// An angle, measured in radians. /// The cosine of decimalValue. procedure Cos(decimalValue: Decimal): Decimal begin exit(DotNetMath.Cos(decimalValue)); end; ////// Returns the hyperbolic cosine of the specified angle. /// /// An angle, measured in radians. /// The hyperbolic cosine of value. procedure Cosh(decimalValue: Decimal): Decimal begin exit(DotNetMath.Cosh(decimalValue)); end; ////// Returns e raised to the specified power. /// /// A number specifying a power. /// The number e raised to the power decimalValue. procedure Exp(decimalValue: Decimal): Decimal begin exit(DotNetMath.Exp(decimalValue)); end; ////// Returns the largest integral value less than or equal to the specified decimal number. /// /// A decimal number. /// The largest integral value less than or equal to decimalValue. procedure Floor(decimalValue: Decimal): Decimal begin exit(DotNetMath.Floor(decimalValue)); end; ////// Returns the remainder resulting from the division of a specified number by another specified number. /// /// A dividend. /// A divisor. /// A number equal to x - (y Q), where Q is the quotient of x / y rounded to the nearest integer (if x / y falls halfway between two integers, the even integer is returned). procedure IEEERemainder(x: Decimal; y: Decimal): Decimal begin exit(DotNetMath.IEEERemainder(x, y)); end; ////// Returns the natural (base e) logarithm of a specified number. /// /// The number whose logarithm is to be found. /// The natural logarithm of decimalValue; that is, ln decimalValue, or log e decimalValue procedure Log(decimalValue: Decimal): Decimal begin exit(DotNetMath.Log(decimalValue)); end; ////// Returns the logarithm of a specified number in a specified base. /// /// The number whose logarithm is to be found. /// The base of the logarithm. /// The logarithm of a specified number in a specified base. procedure Log(a: Decimal; newBase: Decimal): Decimal begin exit(DotNetMath.Log(a, newBase)); end; ////// Returns the base 10 logarithm of a specified number. /// /// A number whose logarithm is to be found. /// The base 10 logarithm of the specified number procedure Log10(decimalValue: Decimal): Decimal begin exit(DotNetMath.Log10(decimalValue)); end; ////// Returns the larger of two decimal numbers. /// /// The first of two decimal numbers to compare. /// The second of two decimal numbers to compare. /// Parameter decimalValue1 or decimalValue2, whichever is larger. procedure "Max"(decimalValue1: Decimal; decimalValue2: Decimal): Decimal begin exit(DotNetMath.Max(decimalValue1, decimalValue2)); end; ////// Returns the smaller of two decimal numbers. /// /// The first of two decimal numbers to compare. /// The second of two decimal numbers to compare. /// Parameter decimalValue1 or decimalValue2, whichever is smaller. procedure "Min"(decimalValue1: Decimal; decimalValue2: Decimal): Decimal begin exit(DotNetMath.Min(decimalValue1, decimalValue2)); end; ////// Returns a specified number raised to the specified power. /// /// A double-precision floating-point number to be raised to a power. /// A double-precision floating-point number that specifies a power. /// The number x raised to the power y. procedure Pow(x: Decimal; y: Decimal): Decimal begin exit(DotNetMath.Pow(x, y)); end; ////// Returns an integer that indicates the sign of a decimal number. /// /// A signed decimal number. /// A number that indicates the sign of value. procedure Sign(decimalValue: Decimal): Integer begin exit(DotNetMath.Sign(decimalValue)); end; ////// Returns the hyperbolic sine of the specified angle. /// /// An angle, measured in radians. /// The hyperbolic sine of value. procedure Sinh(decimalValue: Decimal): Decimal begin exit(DotNetMath.Sinh(decimalValue)); end; ////// Returns the sine of the specified angle. /// /// An angle, measured in radians. /// The sine of a. procedure Sin(decimalValue: Decimal): Decimal begin exit(DotNetMath.Sin(decimalValue)); end; ////// Returns the square root of a specified number. /// /// The number whose square root is to be found. /// The positive square root of decimalValue. procedure Sqrt(decimalValue: Decimal): Decimal begin exit(DotNetMath.Sqrt(decimalValue)); end; ////// Returns the tangent of the specified angle. /// /// An angle, measured in radians. /// The tangent of a. procedure Tan(a: Decimal): Decimal begin exit(DotNetMath.Tan(a)); end; ////// Returns the hyperbolic tangent of the specified angle. /// /// An angle, measured in radians. /// The hyperbolic tangent of value. procedure Tanh(decimalValue: Decimal): Decimal begin exit(DotNetMath.Tanh(decimalValue)); end; ////// Calculates the integral part of a specified decimal number. /// /// A number to truncate. /// The integral part of decimalValue. procedure Truncate(decimalValue: Decimal): Decimal begin exit(DotNetMath.Truncate(decimalValue)); end; }
Hope this helps.
Thanks.
ZHU
Hi,
Yes its possible but you have to put your own logic and use of available method or function of AL code.
Thanks.
André Arnaud de Cal...
294,137
Super User 2025 Season 1
Martin Dráb
232,877
Most Valuable Professional
nmaenpaa
101,158
Moderator