Skip to content

Commit

Permalink
fix format and add sqrt as a function
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel-rubio committed Apr 29, 2016
1 parent de61777 commit c135679
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/ephp_lib_math.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
init_func/0,
init_config/0,

php_round/2,
php_ceil/2,
php_floor/2
php_round/3,
php_ceil/3,
php_floor/3,
php_sqrt/3
]).

-include("ephp.hrl").
Expand All @@ -20,34 +21,42 @@
init_func() -> [
{php_ceil, [{alias, <<"ceil">>}]},
{php_floor, [{alias, <<"floor">>}]},
{php_round, [{alias, <<"round">>}]}
{php_round, [{alias, <<"round">>}]},
{php_sqrt, [{alias, <<"sqrt">>}]}
].

-spec init_config() -> ephp_func:php_config_results().

init_config() -> [].

-spec php_ceil(context(), var_value()) -> integer().
-spec php_ceil(context(), line(), var_value()) -> integer().

php_ceil(_Context, {_, Value}) when is_number(Value) ->
php_ceil(_Context, _Line, {_, Value}) when is_number(Value) ->
ceiling(Value);
php_ceil(_Context, {_, Value}) ->
php_ceil(_Context, _Line, {_, Value}) ->
ceiling(ephp_util:bin_to_float(Value)).

-spec php_floor(context(), var_value()) -> integer().
-spec php_floor(context(), line(), var_value()) -> integer().

php_floor(_Context, {_, Value}) when is_number(Value) ->
php_floor(_Context, _Line, {_, Value}) when is_number(Value) ->
floor(Value);
php_floor(_Context, {_, Value}) ->
php_floor(_Context, _Line, {_, Value}) ->
floor(ephp_util:bin_to_float(Value)).

-spec php_round(context(), var_value()) -> integer().
-spec php_round(context(), line(), var_value()) -> integer().

php_round(_Context, {_, Value}) when is_number(Value) ->
php_round(_Context, _Line, {_, Value}) when is_number(Value) ->
round(Value);
php_round(_Context, {_, Value}) ->
php_round(_Context, _Line, {_, Value}) ->
round(ephp_util:bin_to_float(Value)).

-spec php_sqrt(context(), line(), var_value()) -> float().

php_sqrt(_Context, _Line, {_, Value}) when is_number(Value) ->
math:sqrt(float(Value));
php_sqrt(_Context, _Line, {_, Value}) ->
math:sqrt(ephp_util:bin_to_float(Value)).

-spec floor(number()) -> integer().

floor(X) when X < 0 ->
Expand Down

0 comments on commit c135679

Please sign in to comment.