[Question]
  [
The [Binet formula](https://en.wikipedia.org/wiki/Fibonacci_number#Closed-form_expression) is a closed form expression for the \$n\$'th [Fibonacci number](https://en.wikipedia.org/wiki/Fibonacci_number):
$$F\_n = \frac {\phi^n - (1-\phi)^n} {\sqrt 5}$$
where \$\phi = \frac {1 + \sqrt 5} 2\$ is the [golden ratio](https://en.wikipedia.org/wiki/Golden_ratio). This formula works even when \$n\$ is [negative](https://en.wikipedia.org/wiki/Fibonacci_number#Negafibonacci) or rational, and so can be a basis to calculating "complex Fibonacci numbers".
For example, by setting \$n = \frac 1 2\$, we can calculate \$F\_\frac 1 2\$ as:
$$F\_\frac 1 2 = \frac 1 {\sqrt 5} \left( \sqrt \frac {1+\sqrt 5} 2 - \sqrt \frac {1-\sqrt 5} 2 \right) \\
\approx 0.56886-0.35158i$$
You are to take a floating point, \$-10 \le n \le 10\$, with up to 3 decimals after the point, and output \$F\_n\$, accurate to at least 5 decimal places. You may either round or truncate, so long as it is consistent. You may also choose to input as a rational number if you wish, or as a `(numerator, denominator)` pair. You may also choose whether integers should be suffixed with `.0` or not, so long as it is consistent across all 21 integer inputs.
As the output will be a complex number in all but 21 cases, you may output in any reasonable format for such a type, including outputting as a `(real, imag)` pair. For the integer inputs, the imaginary part will be \$0\$. You may choose whether to output the imaginary part in this case (and returning an integer or float is perfectly fine).
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins
## Test cases
These all round their output, rather than truncate.
```
  n       Re(Fn)     Im(Fn)
-10      -55         0
  1        1         0
 -7       13         0
  3        2         0
  0.5      0.56886  -0.35158
  5.3      5.75045   0.02824
  7.5     16.51666   0.01211
 -1.5      0.21729  -0.92044
 -9.06    34.37587  -6.55646
  9.09    35.50413   0.00157
 -2.54     0.32202   1.50628
  5.991    7.96522   0.00071
 -6.033   -8.08507   0.84377
  8.472   26.36619  -0.00756
```
And a script to output [all possible outputs](https://tio.run/##TY27DsIwDEXn5ivuhg0tT4FEJVZG/iFAC5EaJ4QgUSG@vaSFAQ@27tGx7dt4dbLqujo4i3trfQtjvQsR91uIOQ5K@avBDrTAZGC0ZsYMS6XqhBttj2cNKUG9Nx5DUPRygZR5AL3@20xLLiTFCIKWS0XFYp4qxzC4VJlgthuSyvaSHpyc9U31pAPVJMysMh@MRBq9ys0br3L7baNpOmx1JMkR3EPOtJdpqHSTY81/yFh9@SLmrvsA) in the same format (gets cut off on TIO due to the length).
  
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 30 bytes
```
(h=2/--√5;h^#-(1-h)^#)√.2&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7XyPD1khfV/dRxyxT64w4ZV0NQ90MzThlTaCAnpHa/8DSzNQSh4CizLySaGVduzQH5Vi1uuDkxLy6ai5dQwMdLgUFQyChaw5iGYMIAz1TEGWqB@aZg3m6hhDKUs/ADCQKpC1BfCM9UxOIYktLsDFmegbGYH0WeibmRly1/wE "Wolfram Language (Mathematica) – Try It Online")
Uses \$\frac{\sqrt 5+1}{2}=\frac{2}{\sqrt 5-1}\$. Mathematica's pre-increment/decrement operators still return the desired value when used on (non-variable) non-atoms.
The built-in [`Fibonacci`](https://reference.wolfram.com/language/ref/Fibonacci.html) is a continuous real function, the real part of the Binet formula: \$F\_n=\frac{\phi^n-\cos(\pi n)\phi^{-n}}{\sqrt 5}\$.
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 20 bytes
```
@(n)([1 1;1 0]^n)(2)
```
[Try it online!](https://tio.run/##Rc7PCoAgDMDhe0@xox4cW2YmEfQe/YGIPNYlen0TLPX07ccYXvu9PUfwwxxGcUoxMXDPQMsah1oGLxQTxCcrLwA4U9lSdSGh@WlQ/7S5Ki50SO23EOm@WqNp8gXnONUWSetUO2xs/NkL "Octave – Try It Online")
You know, this classical Fibonacci number formula still works here...
$$
F\_x=\begin{bmatrix}1 & 0\end{bmatrix}\begin{bmatrix}1 & 1 \\ 1 & 0\end{bmatrix}^x\begin{bmatrix}0 \\ 1\end{bmatrix}
$$
---
Aha, after I posted this answer. I try some searching about it. And I finally found out [flawr](https://codegolf.stackexchange.com/users/24877/flawr)'s [previous answer](https://codegolf.stackexchange.com/a/105184/44718) to [Negative Fibonacci Numbers](https://codegolf.stackexchange.com/questions/105183) question. It just using the same codes. Also there are many other answers may simply fit this questions' requirement. I'm not sure if this is a duplicate here, but... They does solve this question with short codes...
[Answer]
# [R](https://www.r-project.org/), ~~60~~ ~~57~~ 41 bytes
~~Just the straightforward golfed implementation. Stole the `sqrt()` = `^.5` trick from Level River St.~~
att and Dominic van Essen golfed off several bytes, thank you. My algebra is rusty! This version takes arguments in complex number notation.
```
function(x,g=.5+5^.5/2)(g^x-(1-g)^x)/5^.5
```
[Try it online!](https://tio.run/##ZZCxbsMwDET3fAWBLjZSMSQlUtKQX/HQAjGypEDRAv57V5KVxk21Sfd0d@Tnerm@ndfL9@396/pxG5bX@Yx61An1JOMwT4sb2M3jtIyn@ljxARzTka4AMMILOFXohw5NBt7UJgPDk@ziTmb/LIPf/5Z/MpV@FWhyuVhKBuAIvbKmDin6B6QYlUJtSUiSJHQo7pzYUNnMNoiFuZflv3HCUXKLy0KhO7mMZJWqkA/oo6ZYoOKpFqzHFSj/QoqlUhu@xBFr7E6CGu5QkbwI1RWUFmTymC7nuuMGRcymIt2J4r24IXnfIZeQklJsUAo@9jhIGKJ0SAy9GW/TFSO1w/oD "R – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 43 bytes
```
lambda x,p=.5+5**.5/2:(p**x-(1-p)**x)/5**.5
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUaFCp8BWz1TbVEtLz1TfyEqjQEurQlfDULdAE8jQ1AeL/y8oyswr0UjT0DU00NTkgvEMkdi65kgcY2RF@kZIPFNjfVQjTFGkdY1RuSZA9aZA9f8B "Python 3 – Try It Online")
-6 bytes thanks to caird coinheringaahing (old version)  
-6 bytes thanks to Noodle9 (old version)
-a lot of bytes after realizing i don't need sympy thanks to Noodle9  
-1 byte thanks to dingledooper
[Answer]
# [MATL](https://github.com/lmendo/MATL), 15 bytes
```
17Lt_Qwhi^d5X^/
```
[Try it online!](https://tio.run/##y00syfn/39DcpyQ@sDwjMy7FNCJO//9/Cz0TcyMA) Or [verify all test cases](https://tio.run/##y00syfmf8N/Q3KckPrA8IzMuxTQiTv@/S8h/XUMDLkMuXXMuYy4DPVMuUz1jLnMgrWsIIiz1DMy4gIQll66RnqkJUNbSEqjYTM/A2JjLQs/E3EgBAA).
### Explanation
```
17L    % Push ϕ (predefined literal)
t_Q    % Duplicate, negate, add 1: gives 1-ϕ
wh     % Swap, concatenate horizontally: gives [1-ϕ, ϕ]
i^     % Input n, element-wise power: gives [(1-ϕ)^n, ϕ^n]
d      % Consecutive difference(s): gives ϕ^n - (1-ϕ)^n
5X^    % Push 5, square root
/      % Divide: gives (ϕ^n - (1-ϕ)^n) / sqrt(5)
       % Implicit display
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 11 bytes
```
ØpC,$*÷5½¤I
```
[Try it online!](https://tio.run/##y0rNyan8///wjAJnHRWtw9tND@09tMTz/@H2R01rtA2ObDR4uGOezpGuY11RbkARawelQ1vd///XNTTQUTDUUdA111Ew1lEw0DPVUTDVA7LMQSxdQzBpqWdgpqMAJC2BHCM9UxOQGktLkDYzPQNjoGoLPRNzIwA "Jelly – Try It Online")
~~Need to find where the 1 byte is :c~~ 1 byte found thanks to Unrelated String :D
[Answer]
# [Ruby](https://www.ruby-lang.org/), ~~39~~ 37 bytes
```
->n{((-p=(1-s=5**0.5)/2)**-n-p**n)/s}
```
[Try it online!](https://tio.run/##XZAxb4QwDIX3/gokFkCKz3ZiJxnoWKlr14qlUm8rQnfqUFX97TQk0AKZHOvze36@fb59zdd@No/jd9OYqW/I3HvpOgRpL9x2nRnN1HVje7n/zHVVjdXxvbw3T2Oby@ePpXyYquurIRyWVl0gI/I3gBmgofzqrU0nwPjhAJA9AfaswCcgJRgOQGpoCJrWQbBCEjImYI@YgBd0kgeQA7uM@ZMaKQipasGIidbghduZMnmO2TQyuqJmIqAO/5h1YL0En7CkK@o0Y4mKezUrkFbLp0imSOKLGoO44WBqmXE5SFoHlbekMdIe8xBVmFc19GsEBbTpJhtmAmAQ9BkLzvpiGsB53qmxglWlkjSJic6/ "Ruby – Try It Online")
With thanks to Dingus for a 1-byte improvement, and Att for a 1-byte improvement and a correction.
Uses the fact that ϕ-1 = 1/ϕ
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`, 36 bytes
```
[ φ over ^ 1 φ - rot ^ - 5 √ / ]
```
[Try it online!](https://tio.run/##JYxBCsIwAATvvmI/kJg2TWv1AeLFi3gShRBTLLVJTVJBxKv4Bj/lH/xIjXqZ3WWXraQK1g3r1WI5n6LRzugjWhkOP9CqNyrU1vh/7E2t7F6jczqES@dqE@D1qddGaY/Z6AqSMCQgBTgYFRCUo4hKki9KynJElCApFVlsyzKOc8o4x4RmRYrbsMHrDnvWDrv4FD2BsyEGAoH344kxtkMrO/ggVUOHDw "Factor – Try It Online")
## Explanation:
It's a quotation (anonymous function) that takes a number as input and leaves a number as output. Factor seamlessly promotes floats and rational numbers to complex numbers when necessary (denoted by `C{ real imaginary }`). Assuming `0.5` is on top of the data stack when this quotation is called...
* `φ` Push phi, the golden ratio, to the data stack.
**Stack:** `0.5 1.618033988749895`
* `over` Put a copy of NOS (next on stack) at TOS (top of stack).
**Stack:** `0.5 1.618033988749895 0.5`
* `^` Raise NOS to the TOS power.
**Stack:** `0.5 1.272019649514069`
* `1` Push `1` to the data stack.
**Stack:** `0.5 1.272019649514069 1`
* `φ` Push phi to the data stack.
**Stack:** `0.5 1.272019649514069 1 1.618033988749895`
* `-` Subtract TOS from NOS.
**Stack:** `0.5 1.272019649514069 -0.6180339887498949`
* `rot` Take the data stack object third from the top and move it to TOS.
**Stack:** `1.272019649514069 -0.6180339887498949 0.5`
* `^` Raise NOS to the TOS power.
**Stack:** `1.272019649514069 C{ 4.813788842079551e-17 0.7861513777574233 }`
* `-` Subtract TOS from NOS.
**Stack:** `C{ 1.272019649514069 -0.7861513777574233 }`
* `5` Push `5` to the data stack.
**Stack:** `C{ 1.272019649514069 -0.7861513777574233 } 5`
* `√` Take the square root of TOS.
**Stack:** `C{ 1.272019649514069 -0.7861513777574233 } 2.23606797749979`
* `/` Divide NOS by TOS.
**Stack:** `C{ 0.568864481005783 -0.3515775842541429 }`
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 65 bytes
```
with(Math)f=x=>[(q=5**.5,q*=(++q/2)**x)/5-cos(x*=PI)/q,-sin(x)/q]
```
[Try it online!](https://tio.run/##jY5Ba4MwGIbv/oochCYao9amTiTdaYMdBrs7oanV6RBjNDhB/O0ubXXnfafne973g@@bD7zPuqpVTiOu@bL8VKqE71yVqGAjOyVQMmpZhGJpMWjb0t0jyxqRS51M9HC02McbciV2@qqBWst0UYCBxHB8D@jBBgD@Ck64mWADj9AHUBI8IFyN428QEe94jzREd7Mn9LBeRZF/M0fiBcHNPJFDuMdGGhuKFKJ74VkJB8BOYNJhnSuQcAwuqX6xgAOKV9nqnRMlXqsxv0KKSJe3Nc9y6H6SZ882XQx2u7@21O3Lv9qZaHpR56QWX/BsTu0MbGBOcq7OOp5RvPwC "JavaScript (Node.js) – Try It Online")
* -1 byte by [Arnauld](https://codegolf.stackexchange.com/users/58563/arnauld)
* -1 byte by [att](https://codegolf.stackexchange.com/users/81203/att)
Simply a translation of given formula
$$ q = \sqrt5\cdot\left(\frac{\sqrt5+1}{2}\right)^x $$
$$ F\_x=\frac{q}{5}-\frac{\left(-1\right)^x}{q}=\left(\frac{q}{5}-\frac{\cos\left(\pi x\right)}{q}\right) + \left(-\frac{\sin\left(\pi x\right)}{q}\right)\cdot i $$
Nothing special here.
I believe it is wrong language to use here. Use some languages with complex numbers support would be a better idea.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~25~~ 24 bytes
```
⭆¹ΣＥ∕Ｘ⊘⊕⟦₂⁵±₂⁵⟧Ｎ₂⁵⎇μ⁻⁰λλ
```
[Try it online!](https://tio.run/##VUy7DsIwDPyVjI4UUBk6sTLQoVVF2RCDaa0SKY/WJEV8fUjGnnS6h60b38ijR5NSz9oFGEKWucUFTkoM0UKxF73piaD3X2K4otlogsaNTJZcyP4xrBGZbt4HqKUSHc0YCHatfMp8adwSQxftKw@VvH9R4k7skH9glWi1ix@olDCysOCcUnWs02Ezfw "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
          ⁵                 Literal `5`
         ₂                  Square root
             ⁵              Literal `5`
            ₂               Square root
           ±               Negated
        ⟦     ⟧             Make into list
       ⊕                    Vectorised increment
      ⊘                     Vectorised halved
     Ｘ                      Vectorised raised to power
               Ｎ            Input as a number
    ∕                       Vectorised divide by
                 ⁵          Literal `5`
                ₂           Square root
   Ｅ              ⎇μ⁻⁰λλ    Negate the second element
  Σ                         Sum the elements
⭆¹                          Stringify
```
The version of Charcoal on TIO doesn't really support complex numbers, but as it happens the `Power` of a negative number to a floating-point value will return a complex result; I just have to be careful not to use operations such as `Negate` and `Cast` where Charcoal will get confused as to which overload to use.
18 bytes using the newer version of Charcoal on ATO:
```
Ｉ↨∕Ｘ⊘⊕⟦±₂⁵₂⁵⟧Ｎ₂⁵±¹
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m70iOSOxKDk_MWfBgqWlJWm6FjfbA4oy80o0nBOLSzScEotTNVwyyzJTUjUC8stTizQ8EnPKUlM0PPOSi1JzU_NKgOxov9T0xJJUjeDC0sSi1KD8_BINU01NHQUUfixIxDOvoLTErzQ3CWgQhgogH2qQoSYQWC8pTkouhjpqebSSblmOUuxiAz1TiAgA "Charcoal – Attempt This Online") Link is to verbose version of code. Explanation: The version of Charcoal on ATO can use "base -1" conversion to take the difference of a list of two complex numbers saving 5 bytes and also can directly cast a complex number to string saving a further 1 byte. (Note that the difference has the opposite sign to the TIO code so I've swapped the two list elements to compensate.)
[Answer]
# [J](http://jsoftware.com/), 25 bytes
```
%:@5%~[:-/(-:1+(,-)%:5)&^
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/Va0cTFXroq109TV0rQy1NXR0NVWtTDXV4v5rcqUmZ@QrpCnEGxrAmIYwhoGeKYxpjmDGG@qZ/gcA "J – Try It Online")
[Answer]
# Java + Apache Commons Math, ~~138~~ ~~136~~ 134 bytes
```
n->{var a=Math.sqrt(5);return new org.apache.commons.math3.complex.Complex(.5-a/2).pow(n).negate().add(Math.pow(a/2+.5,n)).divide(a);}
```
*Saved 2 bytes thanks to [Original Original Original VI](https://codegolf.stackexchange.com/users/95792).*
*Saved 2 bytes thanks to [tsh](https://codegolf.stackexchange.com/users/44718).*
[Answer]
# [APL (Dyalog Extended)](https://github.com/abrudz/dyalog-apl-extended), ~~23~~ 22 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319 "When can APL characters be counted as 1 byte each?") ([SBCS](https://github.com/abrudz/SBCS ".dyalog files using a single byte character set"))
Anonymous tacit prefix function. Complex results are returned as \$Re\$`J`\$Im\$.
```
-/s÷⍨(2÷⍨1(+,-)s←√5)*⊢
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/X1e/@PD2R70rNIzAlKGGto6uZvGjtgmPOmaZamo96lr0Pw3E6@171NX8qHfNo94th9YbP2qb@KhvanCQM5AM8fAM/p@ma2igAARcaQoKhlCGrjlMxBjGMNAzhTBM9YwhDHOoiK4hjGGpZ2AGlgIyLMEiRnqmJlBdlpaGIBEzPQNjY5CIhZ6JuREA "APL (Dyalog Extended) – Try It Online")
`(`…`)*⊢` raise the following value to the power of the argument:
 `√5` square root of five: \$\sqrt5\$
 `s←` store that as `s` and return the value: \$\sqrt5\$
 `1(+,-)` that, added to and subtracted from one: \$1±\sqrt5\$
 `2÷⍨` half of that: \$1±\sqrt5\over2\$
Now we have \$\left(\frac{1±\sqrt5}2\right)^n\$
`s÷⍨` divide that by `s`: \$\left(\frac{1±\sqrt5}2\right)^n\over\sqrt5\$
`-/` the difference between them: \${\left(\frac{1+\sqrt5}2\right)^n\over\sqrt5}-{\left(\frac{1-\sqrt5}2\right)^n\over\sqrt5}\$
[Answer]
# Excel, 73 bytes
```
=LET(q,5^0.5*((5^0.5+1)/2)^A1,a,PI()*A1,IF({1,0},q/5-COS(a)/q,-SIN(a)/q))
```
Using [tsh's formula](https://codegolf.stackexchange.com/a/223003/101349)
[Answer]
# MATLAB, 43 bytes
[Try it online](https://tio.run/##lU/baoQwEH33K@Yx6eri5KKrIV9StrDY2AbcWKztQ3/eziTPCy1yJnPmXMB12m/f4TjmrzTtcU2Q/CTuskp@28JMm1v8Z/wJItUo3bxuED2OSxU8nu3pbJ9Eg/IljmpcXBKhHqUvz2kLH/fbLpKIxOolpLf9XQTJNSG9ZhyTeFZgoIOLgxYUwThAWiyYq6xIZqIdeSxYR8YHAkcbLMpfGvnAdX1BsWQUkwba6QBIBTSpTRnQCL3i2bWAA@fhwiIMNC30jqnJR0UODbr7T12bw9jRn5ACjRoeFiKZ@WsUx7DA5RMTdZXHLw)
```
p=.5+sqrt(5/4);F=@(n)(p^n-(1-p)^n)/sqrt(5);
```
F is an anonymous function that you plug n into.
]