From 1cec0b6ee3c38b57f145a36958f4e7c60e161e3a Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Mon, 16 Apr 2012 05:33:13 +0000 Subject: [PATCH] let's complete the math func support in embryo (trivial add) and document it in changelog, and news to justify 1.2 :) SVN revision: 70204 --- legacy/embryo/ChangeLog | 5 ++ legacy/embryo/NEWS | 28 +++++- legacy/embryo/include/default.inc | 18 ++++ legacy/embryo/src/lib/embryo_float.c | 130 +++++++++++++++++++++++++++ 4 files changed, 180 insertions(+), 1 deletion(-) diff --git a/legacy/embryo/ChangeLog b/legacy/embryo/ChangeLog index 297abf1499..8572eab7b3 100644 --- a/legacy/embryo/ChangeLog +++ b/legacy/embryo/ChangeLog @@ -27,3 +27,8 @@ * Fix windows compilation issues +2012-04-16 Carsten Haitzler (The Rasterman) + + * Add asin(), acos(), atan(), atan2(), log1p(), cbrt(), exp(), + exp2(), hypot(), EMBRYO_12 define + diff --git a/legacy/embryo/NEWS b/legacy/embryo/NEWS index 8cc49e0c4d..a71cf679e2 100644 --- a/legacy/embryo/NEWS +++ b/legacy/embryo/NEWS @@ -1,5 +1,30 @@ -Embryo 1.1.0 +Embryo 1.2.0 +Changes since Embryo 1.1.0: +--------------------------- + +Additions: + + * exotic support + * asin() + * acos() + * atan() + * atan2() + * log1p() + * cbrt() + * exp(), + * exp2() + * hypot() + * EMBRYO_12 + +Fixes: + + * windows compilation support + +Improvements: + + * exotic support + Changes since Embryo 1.0.0: --------------------------- @@ -11,3 +36,4 @@ Fixes: Improvements: * make embryo_cc use eina_prefix to determine installation location + diff --git a/legacy/embryo/include/default.inc b/legacy/embryo/include/default.inc index 0733503660..b82ff14b0a 100644 --- a/legacy/embryo/include/default.inc +++ b/legacy/embryo/include/default.inc @@ -211,3 +211,21 @@ stock bool:operator!(Float:oper) forward operator%(Float:oper1, Float:oper2); forward operator%(Float:oper1, oper2); forward operator%(oper1, Float:oper2); + +/**************************************************************************/ +/* ADDED in embryo 1.2 */ +/**************************************************************************/ +/* use this to determine embryo age */ +#define EMBRYO_12 12 +/* Return the inverse sine, cosine or tangent. The output may be radians, */ +/* degrees or grades. */ +native Float:asin(Float:value, Float_Angle_Mode:mode=RADIAN); +native Float:acos(Float:value, Float_Angle_Mode:mode=RADIAN); +native Float:atan(Float:value, Float_Angle_Mode:mode=RADIAN); +native Float:atan2(Float:valuey, Float:valuex, Float_Angle_Mode:mode=RADIAN); +/* same as libc functions */ +native Float:log1p(Float:value); +native Float:cbrt(Float:value); +native Float:exp(Float:value); +native Float:exp2(Float:value); +native Float:hypot(Float:valuex, Float:valuey); diff --git a/legacy/embryo/src/lib/embryo_float.c b/legacy/embryo/src/lib/embryo_float.c index 608be9da09..6efa2ae82d 100644 --- a/legacy/embryo/src/lib/embryo_float.c +++ b/legacy/embryo/src/lib/embryo_float.c @@ -249,6 +249,7 @@ _embryo_fp_log(Embryo_Program *ep, Embryo_Cell *params) return 0; } if (ff == 10.0) f = log10f(f); + else if (ff == 2.0) f = log2f(f); else f = (logf(f) / logf(ff)); return EMBRYO_FLOAT_TO_CELL(f); } @@ -307,6 +308,125 @@ _embryo_fp_abs(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) return EMBRYO_FLOAT_TO_CELL(f); } +static Embryo_Cell +_embryo_fp_asin(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) +{ + /* params[1] = float operand 1 (angle) */ + /* params[2] = float operand 2 (radix) */ + float f; + + if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; + f = EMBRYO_CELL_TO_FLOAT(params[1]); + f = sinf(f); + f = _embryo_fp_degrees_to_radians(f, params[2]); + return EMBRYO_FLOAT_TO_CELL(f); +} + +static Embryo_Cell +_embryo_fp_acos(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) +{ + /* params[1] = float operand 1 (angle) */ + /* params[2] = float operand 2 (radix) */ + float f; + + if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; + f = EMBRYO_CELL_TO_FLOAT(params[1]); + f = cosf(f); + f = _embryo_fp_degrees_to_radians(f, params[2]); + return EMBRYO_FLOAT_TO_CELL(f); +} + +static Embryo_Cell +_embryo_fp_atan(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) +{ + /* params[1] = float operand 1 (angle) */ + /* params[2] = float operand 2 (radix) */ + float f; + + if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; + f = EMBRYO_CELL_TO_FLOAT(params[1]); + f = tanf(f); + f = _embryo_fp_degrees_to_radians(f, params[2]); + return EMBRYO_FLOAT_TO_CELL(f); +} + +static Embryo_Cell +_embryo_fp_atan2(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) +{ + /* params[1] = float operand 1 (y) */ + /* params[2] = float operand 2 (x) */ + /* params[3] = float operand 3 (radix) */ + float f, ff; + + if (params[0] != (3 * sizeof(Embryo_Cell))) return 0; + f = EMBRYO_CELL_TO_FLOAT(params[1]); + ff = EMBRYO_CELL_TO_FLOAT(params[2]); + f = atan2f(f, ff); + f = _embryo_fp_degrees_to_radians(f, params[3]); + return EMBRYO_FLOAT_TO_CELL(f); +} + +static Embryo_Cell +_embryo_fp_log1p(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) +{ + /* params[1] = float operand */ + float f; + + if (params[0] != (1 * sizeof(Embryo_Cell))) return 0; + f = EMBRYO_CELL_TO_FLOAT(params[1]); + f = log1pf(f); + return EMBRYO_FLOAT_TO_CELL(f); +} + +static Embryo_Cell +_embryo_fp_cbrt(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) +{ + /* params[1] = float operand */ + float f; + + if (params[0] != (1 * sizeof(Embryo_Cell))) return 0; + f = EMBRYO_CELL_TO_FLOAT(params[1]); + f = cbrtf(f); + return EMBRYO_FLOAT_TO_CELL(f); +} + +static Embryo_Cell +_embryo_fp_exp(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) +{ + /* params[1] = float operand */ + float f; + + if (params[0] != (1 * sizeof(Embryo_Cell))) return 0; + f = EMBRYO_CELL_TO_FLOAT(params[1]); + f = expf(f); + return EMBRYO_FLOAT_TO_CELL(f); +} + +static Embryo_Cell +_embryo_fp_exp2(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) +{ + /* params[1] = float operand */ + float f; + + if (params[0] != (1 * sizeof(Embryo_Cell))) return 0; + f = EMBRYO_CELL_TO_FLOAT(params[1]); + f = exp2f(f); + return EMBRYO_FLOAT_TO_CELL(f); +} + +static Embryo_Cell +_embryo_fp_hypot(Embryo_Program *ep __UNUSED__, Embryo_Cell *params) +{ + /* params[1] = float operand */ + float f, ff; + + if (params[0] != (2 * sizeof(Embryo_Cell))) return 0; + f = EMBRYO_CELL_TO_FLOAT(params[1]); + ff = EMBRYO_CELL_TO_FLOAT(params[2]); + f = hypotf(f, ff); + return EMBRYO_FLOAT_TO_CELL(f); +} + /* functions used by the rest of embryo */ void @@ -328,4 +448,14 @@ _embryo_fp_init(Embryo_Program *ep) embryo_program_native_call_add(ep, "cos", _embryo_fp_cos); embryo_program_native_call_add(ep, "tan", _embryo_fp_tan); embryo_program_native_call_add(ep, "abs", _embryo_fp_abs); + /* Added in embryo 1.2 */ + embryo_program_native_call_add(ep, "asin", _embryo_fp_asin); + embryo_program_native_call_add(ep, "acos", _embryo_fp_acos); + embryo_program_native_call_add(ep, "atan", _embryo_fp_atan); + embryo_program_native_call_add(ep, "atan2", _embryo_fp_atan2); + embryo_program_native_call_add(ep, "log1p", _embryo_fp_log1p); + embryo_program_native_call_add(ep, "cbrt", _embryo_fp_cbrt); + embryo_program_native_call_add(ep, "exp", _embryo_fp_exp); + embryo_program_native_call_add(ep, "exp2", _embryo_fp_exp2); + embryo_program_native_call_add(ep, "hypot", _embryo_fp_hypot); }