Although FileMaker includes many common mathematical operations and formulas, no list can be exhaustive. This function applies the Pythagorean Theorem (a2 + b2 = c2) to generate the length of a hypotenuse (the leg of a right triangle opposite the right angle).
fnHypotenuse ( 3; 4 ) returns 5.
// returns the length of a hypotenuse based on the Pythagorean Theorem ( a^2 + b%2 = c%2 ) // input: two numbers // output: number Let ([ a2 = leg1Length * leg1Length; b2 = leg2Length * leg2Length; c2 = a2 + b2 ]; Sqrt ( c2 ) )
FileMaker provides a built-in function for calculating the square root of a number, but not the nth root.
fnNthRoot ( 8; 3 ) returns 2.
fnNthRoot ( 256; 4 ) returns 4.
// returns the nth root of number // input: two numbers // output: number Exp ( Ln ( number ) / root )
This function computes the area of a regular polygon, given the number of sides and the radius of the polygon. (A regular polygon is a polygon in which all sides are of equal length.) The radius is the distance from the center of the polygon to any vertex. In other words, the radius of the polygon is the radius of a circle that exactly circumscribes the polygon.
A pentagon with a radius of three meters would be evaluated like so: fnPolyAreaBySide ( 5 ; 3 ) which returns 21.399 (rounded) square meters.
An equilateral triangle with a radius of 4 inches: fnPolyAreaByRadius ( 3 ; 4 ) returns 20.723 square inches (rounded).
// computes the area of a regular polygon // input: // numberOfSides = the number of the polygons sides // radius = distance from the center of the polygon to a vertex // output: area of the polygon in aquare units // requires fnPolyAreaFromSideLength Let ([ n = numberOfSides; r = radius; sideLength = 2 * r * Sin ( Pi/n ); result = fnPolyAreaFromSideLength ( n ; sideLength ) ]; result )
This function computes the area of a regular polygon, given the number of sides and the length of each side.
A hexagon with sides of length 3: fnPolyAreaBySide ( 6 ; 3 ) returns 23.382 (rounded) units squared.
An equilateral triangle with sides of length 4: fnPolyAreaBySide ( 3 ; 4 ) returns 6.928 (rounded) units squared.
// computes the area of a regular polygon // input: // numberOfSides = the number of the polygons sides // sideLength = the length of one side // output: area of the polygon in units squared Let ([ n = numberOfSides; l = sideLength; result = ( n * l^2) / ( 4 * Tan( Pi/n ) ) ]; result )
The Random function in FileMaker returns a value from 0 to 1, but developers almost always need a random number within a range of numbers. For example, if you need a number between 10 and 50, the formula would be
Int ( Random * 41 ) + 10
This makes code somewhat difficult to read and requires that you think through the formula each time you need it. The fnRandomInRange() function hides this logic in an easy-to-use function.
fnRandomInRange ( 3; 7 ) might return 4.
// returns a random number from low to high range // input: two numbers // output: a random number within the range between the two Int ( Random * ( highNumber - lowNumber + 1 )) + lowNumber
This function computes the distance between two points on the surface of the Earth, given in terms of decimal latitude and longitude. The coordinates must be decimalin other words, 45.5, not 45 degrees 30 minutesand must be given in degrees.
The function can return results in miles or kilometers. Any "units" value beginning with "m" will yield miles; otherwise, the function will return kilometers.
The computation is based on the "haversine formula" and assumes a reasonable degree of mathematical precision in the software, which FileMaker possesses.
See http://en.wikipedia.org/wiki/Haversine_formula for further details.
The distance between San Francisco and Chicago in miles is fnSphericalDistance ( 37.799; 122.461; 41.886; 87.623; "miles" ), which returns 1856.62.
// computes distance between two points on Earths surface // input: // lat1, long2, lat2, long2 = lat and long of two points, in DECIMAL DEGREES // units = "miles" or "km" // output: distance between the two points in miles or kilometers Let([ D = Case( Trim(Lower(Left(units;1))) = "m"; 3958.75;6367.45 ); // diameter of Earth in miles or km lat1R = Radians(lat1); lat2R = Radians(lat2); long1R = Radians(long1); long2R = Radians(long2); dlat = lat2R - lat1R; dlong = long2R - long1R; a = (Sin(dlat/2))^2 + Cos(lat1R) * Cos(lat2R) * (Sin(dlong/2))^2; c = 2 * Atan(Sqrt(a)/Sqrt(1-a)); result = D * c ]; result )
: FileMaker Specifications
FileMaker 8 Product Line
Specifications and Storage Limits
Field Types and Import/Export Formats
: Calculation Functions
Working with Calculations Primer
: Custom Functions
Custom Functions Primer
Useful Custom Functions
: Script Steps
Script Step Reference
: Quick Reference
FileMaker Error Codes
FileMaker Keyboard Shortcuts
FileMaker Network Ports
FileMaker Server Command Line Reference
FileMaker XML Reference
: Other Resources
Where to Go for More Information