Skip to content

Commit

Permalink
[dylan] Add ilog2.
Browse files Browse the repository at this point in the history
This is about to be added to Open Dylan, so add it to Mindy for
compatibility.

* libraries/dylan/transcendental.dylan
  (ilog2): Implement.

* libraries/dylan/library.dylan
  (module %Transcendental): Export ilog2.

* documentation/source/transcendentals.rst
  (log): Link to ilog2.
  (logn): Link to ilog2.
  (ilog2): Document.
  • Loading branch information
waywardmonkeys committed Nov 9, 2015
1 parent da9f00f commit c564a42
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
26 changes: 26 additions & 0 deletions documentation/source/transcendentals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ The following names are exported from the ``Transcendental`` module of the
:seealso:

- :gf:`exp`
- :func:`ilog2`
- :gf:`logn`

.. generic-function:: logn
Expand All @@ -402,6 +403,30 @@ The following names are exported from the ``Transcendental`` module of the
:seealso:

- :gf:`exp`
- :func:`ilog2`
- :gf:`log`

.. function:: ilog2

:summary:
Returns the base two logarithm of its argument, truncated to an
integer.

:signature: ilog2 x => y

:parameter x: An instance of :drm:`<integer>`.
:value y: An instance of :drm:`<integer>`.

:description:

Returns the integer base two logarithm of ``x``, that is the
greatest integer less than or equal to the exact base two logarithm
of ``x``.

:seealso:

- :gf:`exp`
- :func:`logn`
- :gf:`log`

.. generic-function:: exp
Expand All @@ -422,6 +447,7 @@ The following names are exported from the ``Transcendental`` module of the
:seealso:

- :gf:`^`
- :func:`ilog2`
- :gf:`log`
- :gf:`logn`

Expand Down
1 change: 1 addition & 0 deletions libraries/dylan/library.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,5 @@ define module %Transcendental
exp, log, logn, sqrt, isqrt,
$single-pi, $single-e, $double-pi, $double-e },
export: all;
export ilog2;
end module %Transcendental;
5 changes: 3 additions & 2 deletions libraries/dylan/transcendental.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ define method \^ (num1 :: <double-float>, num2 :: <single-float>)
num1 ^ as(<double-float>, num2);
end method;



define function ilog2 (x :: <integer>) => (result :: <integer>)
truncate(log(as(<single-float>, x)) / log(2.0s0))
end function ilog2;

0 comments on commit c564a42

Please sign in to comment.