Skip to content

Commit 036533d

Browse files
committed
doc: add doc and examples for fibonaccinum
1 parent b5b8570 commit 036533d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/numbers.jl

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,43 @@ function narayana(bn::Integer,bk::Integer)
163163
div(binomial(n, k)*binomial(n, k - 1) , n)
164164
end
165165

166+
"""
167+
fibonaccinum(n)
168+
169+
Compute the ``n``th Fibonacci number, ``F_n``, given by:
170+
```math
171+
F_0 = 0
172+
\\\\
173+
F_1 = 1
174+
\\\\
175+
F_n = F_{n-1} + F_{n-2}
176+
```
177+
178+
# Examples
179+
```jldoctest
180+
julia> [ fibonaccinum(i) for i in 0:5 ]
181+
6-element Vector{BigInt}:
182+
0
183+
1
184+
1
185+
2
186+
3
187+
5
188+
189+
julia> fibonaccinum(13)
190+
233
191+
192+
julia> fibonaccinum(-1)
193+
ERROR: DomainError with -1:
194+
n must be nonnegative
195+
Stacktrace:
196+
[...]
197+
```
198+
199+
# References
200+
- [Fibonacci sequence - Wikipedia](https://en.wikipedia.org/wiki/Fibonacci_sequence)
201+
- [DLMF: §26.11 Fibonacci number](https://dlmf.nist.gov/26.11#p4)
202+
"""
166203
function fibonaccinum(n::Integer)
167204
if n < 0
168205
throw(DomainError(n, "n must be nonnegative"))

0 commit comments

Comments
 (0)