1
0
Fork 0

added PI() function

This commit is contained in:
Jan Steemann 2016-06-03 09:25:46 +02:00
parent 54de1a5e52
commit 5c0dd05308
7 changed files with 55 additions and 1 deletions

View File

@ -309,6 +309,18 @@ PERCENTILE( [1, 2, 3, 4], 50, "rank" ) // 2
PERCENTILE( [1, 2, 3, 4], 50, "interpolation" ) // 2.5
```
!SUBSECTION PI()
`PI() → pi`
Return pi.
- returns **pi** (number): the first few significant digits of pi (3.141592653589793)
```js
PI() // 3.141592653589793
```
!SUBSECTION POW()
`POW(base, exp) → num`

View File

@ -230,6 +230,8 @@ struct FunctionDefiner {
&Functions::Radians});
add({"DEGREES", "AQL_DEGREES", "n", true, true, false, true, true,
&Functions::Degrees});
add({"PI", "AQL_PI", "", true, true, false, true, true,
&Functions::Pi});
}
void addListFunctions() {

View File

@ -3242,6 +3242,16 @@ AqlValue Functions::Degrees(arangodb::aql::Query* query,
return NumberValue(trx, radians * (180.0 / std::acos(-1.0)), true);
}
/// @brief function PI
AqlValue Functions::Pi(arangodb::aql::Query* query,
arangodb::AqlTransaction* trx,
VPackFunctionParameters const& parameters) {
ValidateParameters(parameters, "PI", 0, 0);
// acos(-1) == PI
return NumberValue(trx, std::acos(-1.0), true);
}
/// @brief function RAND
AqlValue Functions::Rand(arangodb::aql::Query* query,
arangodb::AqlTransaction* trx,

View File

@ -209,6 +209,8 @@ struct Functions {
VPackFunctionParameters const&);
static AqlValue Degrees(arangodb::aql::Query*, arangodb::AqlTransaction*,
VPackFunctionParameters const&);
static AqlValue Pi(arangodb::aql::Query*, arangodb::AqlTransaction*,
VPackFunctionParameters const&);
static AqlValue Rand(arangodb::aql::Query*, arangodb::AqlTransaction*,
VPackFunctionParameters const&);
static AqlValue FirstDocument(arangodb::aql::Query*,

View File

@ -94,7 +94,7 @@ var AqlHighlightRules = function() {
var builtinFunctions = (
"(to_bool|to_number|to_string|to_list|is_null|is_bool|is_number|is_string|is_list|is_document|typename|" +
"concat|concat_separator|char_length|lower|upper|substring|left|right|trim|reverse|contains|" +
"log|log2|log10|exp|exp2|sin|cos|tan|asin|acos|atan|atan2|radians|degrees|regex|" +
"log|log2|log10|exp|exp2|sin|cos|tan|asin|acos|atan|atan2|radians|degrees|pi|regex|" +
"like|floor|ceil|round|abs|rand|sqrt|pow|length|min|max|average|sum|median|variance_population|" +
"variance_sample|first|last|unique|matches|merge|merge_recursive|has|attributes|values|unset|unset_recursive|keep|" +
"near|within|within_rectangle|is_in_polygon|fulltext|paths|traversal|traversal_tree|edges|stddev_sample|stddev_population|" +

View File

@ -3105,6 +3105,16 @@ function AQL_DEGREES (value) {
return NUMERIC_VALUE(value * (180 / Math.PI));
}
////////////////////////////////////////////////////////////////////////////////
/// @brief pi
////////////////////////////////////////////////////////////////////////////////
function AQL_PI () {
'use strict';
return Math.PI;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief get the length of a list, document or string
////////////////////////////////////////////////////////////////////////////////
@ -8399,6 +8409,7 @@ exports.AQL_ATAN = AQL_ATAN;
exports.AQL_ATAN2 = AQL_ATAN2;
exports.AQL_RADIANS = AQL_RADIANS;
exports.AQL_DEGREES = AQL_DEGREES;
exports.AQL_PI = AQL_PI;
exports.AQL_LENGTH = AQL_LENGTH;
exports.AQL_FIRST = AQL_FIRST;
exports.AQL_LAST = AQL_LAST;

View File

@ -51,6 +51,23 @@ function ahuacatlNumericFunctionsTestSuite () {
return {
////////////////////////////////////////////////////////////////////////////////
/// @brief test pi function
////////////////////////////////////////////////////////////////////////////////
testPi : function () {
var expected = 3.141592653589793;
var query = "RETURN PI()";
assertAlmostEqual(expected, getQueryResults(query)[0]);
query = "RETURN NOOPT(PI())";
assertAlmostEqual(expected, getQueryResults(query)[0]);
query = "RETURN NOOPT(V8(PI()))";
assertAlmostEqual(expected, getQueryResults(query)[0]);
},
////////////////////////////////////////////////////////////////////////////////
/// @brief test log function
////////////////////////////////////////////////////////////////////////////////