Skip to content

Commit

Permalink
Add digits, fibonacci
Browse files Browse the repository at this point in the history
  • Loading branch information
LivInTheLookingGlass committed Jul 7, 2024
1 parent 0f30305 commit ff3f8a2
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/c.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Library Code
c/bcd
c/digits
c/factors
c/fibonacci
c/iterator
c/macros
c/math
Expand Down
39 changes: 39 additions & 0 deletions docs/c/digits.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
digits.h
========

.. c:namespace-push:: digits
.. c:type:: digit_counter
Implements the :c:macro:`Iterator <c.iterator.IteratorHead>` API
and yields successive decimal digits of a given number.

.. c:member:: unsigned char (*iterator_function)(*digit_counter)
The function to advance the iterator and return the next element.
.. c:member:: bool exhausted : 1
An indicator that tells you if the iterator is exhausted.
.. c:member:: bool started : 1
An indicator that tells you if the interator has moved at all.
.. c:member:: bool phase : 1
An indicator that flips every time the iterator moves.
.. c:member:: unsigned char *digits
This array holds the individual digits of a parsed integer.
.. c:member:: size_t idx
This represents the current position in :c:member:`digits`.
.. c:function:: digit_counter digits(uintmax_t n)
.. c:function:: void free_digit_counter(digit_counter dc)
.. c:namespace-pop::
38 changes: 38 additions & 0 deletions docs/c/fibonacci.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
fibonacci.h
========

.. c:namespace-push:: fibonacci
.. c:type:: fibonacci
Implements the :c:macro:`Iterator <c.iterator.IteratorHead>` API
and yields successive Fibonacci numbers.

.. c:member:: uintmax_t (*iterator_function)(*digit_counter)
The function to advance the iterator and return the next element.

.. c:member:: bool exhausted : 1
An indicator that tells you if the iterator is exhausted.

.. c:member:: bool started : 1
An indicator that tells you if the interator has moved at all.

.. c:member:: bool phase : 1
An indicator that flips every time the iterator moves.

.. c:member:: uintmax_t a
.. c:member:: uintmax_t b
.. c:member:: uintmax_t limit
This represents the largest number the iterator is allowed to yield.

.. c:function:: fibonacci fibonacci1(uintmax_t limit)
.. c:function:: fibonacci fibonacci0()
.. c:namespace-pop::

0 comments on commit ff3f8a2

Please sign in to comment.