[Question]
  [
The sequence of Fibonacci numbers is defined as follows:
\$
F\_0 = 0 \\
F\_1 = 1 \\
F\_n = F\_{n-1} + F\_{n-2}
\$
Given a Fibonacci number, return the previous Fibonacci number in the sequence. You do not need to handle the inputs \$ 0 \$ or \$ 1 \$, nor any non-Fibonacci numbers.
Errors as a result of floating point inaccuracies are permitted.
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest code in bytes wins.
  
[Answer]
# [Vyxal](https://github.com/Vyxal/Vyxal), 4 bytes
```
kg/ṙ
```
[Try it Online!](https://vyxal.pythonanywhere.com/#WyIiLCIiLCJrZy/huZkiLCIiLCIyIl0=)
Port of Unmitigated's JavaScript answer
```
  /  # Divide by...
kg   # Phi
   ṙ # Round
```
[Answer]
# JavaScript, ~~21~~ 17 bytes
```
n=>n*5**.5-n+1>>1
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNEts/ifZvs/z9YuT8tUS0vPVDdP29DOzvB/QVFmXolGmoaRpiYXjG2MxDZFYlsgsQ2RFRkZIus2QdaOot8S2QAToLr/AA)
-4 bytes thanks to [att](https://codegolf.stackexchange.com/users/81203).
[Answer]
# [R](https://www.r-project.org), ~~23~~ ~~22~~ 20 bytes
*Edit: -1 byte thanks to pajonk, then -2 bytes thanks to att*
```
\(x)(x*5^.5-x+1)%/%2
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMHqgqLUsvi0zCQFG92lpSVpuhZbYjQqNDUqtEzj9Ex1K7QNNVX1VY0gUjc1YKo1kjWMdIx1THUsdAyNdYwMdYxNdEyBPEsdQxMTTU0uiPoFCyA0AA)
The ratio between consecutive fibonacci numbers famously converges towards [the golden ratio phi](https://en.wikipedia.org/wiki/Golden_ratio), equal to `(1+5^.5)/2`.  
This is sufficiently accurate that rounding produces the correct value for all fibonacci numbers, including even the second `1` at the start which we don't need to handle here.
(Edit after reading some other answers: this was independently-derived, but is also the approach taken by [Luis Mendo](https://codegolf.stackexchange.com/a/247844/95126) and [unmitigated](https://codegolf.stackexchange.com/a/247840/95126))
[Answer]
# [R](https://www.r-project.org), 27 bytes
```
\(x){while(x>T)T=F+(F=T);F}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m72waMHqgqLUsvi0zCQFG92lpSVpuha7YzQqNKvLMzJzUjUq7EI0Q2zdtDXcbEM0rd1qISrWwvRoGBprckHEFiyA0AA)
Similar to [this answer](https://codegolf.stackexchange.com/a/247836/67312), iterates through the Fibonacci sequence until `T==x` and returns `F`.
[Answer]
# x86-64 assembly, ~~13~~ 12 bytes
```
6a 01 58 99 92 01 c2 39 fa 75 f9 c3
```
In assembly:
```
previous:
    push 1
    pop rax
    cdq     # zeroes rdx
previous_loop:
    xchg eax,edx
    add edx,eax
    cmp edx,edi
    jne previous_loop
    ret
```
[Try it online!](https://tio.run/##bVHRbtswDHw2v4JoMOwlMeqkW9sA3cuA/cQ2GIxFO@pkyZPkxP76jLaStClmwDZF3h1PJIXA7c6Mq6aqTgtKJw543FPkA3vUAbXF704xBq6idhbJKnR97PqIw6Cwdr6lCAvlONjPEY/O/0FdYzVxhG7INyIU92Sx0x3jrq9r9rDYiYAICmGinRUFFrHtq720GY80Qq5tZFOG0UYa0LrOc60HyBVFghDJx/Jse9yepHjQrg9bQHm6PuyxSKHr0NMwx5X6CxdgaZzrEnqo9g0yDUtWCUdKocRLvvDaLp2Vns@vlvFGZ856jie26s0UXKLSsH15X1rd2gcIFdm6DNFr22why1OEd5/6X/ZOPMso/l/Gl2@YQNLjioCatOk9ly2HQA1v4Ur5IRVW@cT4AJpdYo4r/FAAyCMPUX6NcTsy2JK2MH3ES@h36EO3fJoT56lmrTtIVi@lAplhQq/08uf7W/6GrCJjcM5BFjnEtAOZefZqGGVeSYcnqghdGJfJQ3azuIQNV@y168303kSmpHSS1V6Ng/QU89P605WyaacFrGFdwOYBigd5nzZfN0XxfL9BWD8/Fuviy/3j5h8 "Assembly (gcc, x64, Linux) – Try It Online")
Uses the usual calling convention of taking the first argument in `rdi` and returning in `rax`. It's also valid x86-32, just with `edi` and `eax` instead.
It's pretty simple- it just explicitly computes Fibonacci numbers and returns if the new number is equal to the input. At the end of a loop, `rdx` contains the next Fibonacci number and `rax` contains the previous. If `rdx` is equal to the input `rdi`, then the loop terminates (and thus `rax`, the previous number, is returned). Otherwise the two are swapped, and the loop begins again.
This uses 32-bit registers to save a few bytes, so it only works up to the 47th Fibonacci number, `2971215073`. It can be expanded to work with 64-bit numbers by changing all the registers to 64-bit, at the cost of 2 bytes:
```
6a 01 58 99 48 0f c1 c2 48 39 fa 75 f7 c3
```
The added bytes are the REX.W (`0x48`) prefix that swaps the operand size to 64-bit. `xchg rax,rdx; add rdx,rax` is also replaced with `xadd rdx,rax`, which is shorter because it uses one fewer REX.W prefix.
-1 byte thanks to [@PeterCordes](https://codegolf.stackexchange.com/users/30206/peter-cordes).
[Answer]
# [Factor](https://factorcode.org/) + `math.unicode`, ~~21~~ ~~19~~ ~~18~~ 14 bytes
```
[ φ / round ]
```
[Try it online!](https://tio.run/##S0tMLskv@h8a7OnnbqWQm1iSoVBQlFpSUllQlJlXopCdWpSXmgMW10vOzysuScwrKYZwS/Myk/NTUiGctNK85JJMoAIFay4uE0MLQ67/0Qrn2xT0FYryS/NSFGL/Jyfm5Cjo/QcA "Factor – Try It Online")
-4 thanks to @DominicvanEssen!
Divide the input by the golden ratio and round the result.
[Answer]
# [C(gcc)](https://gcc.gnu.org/c99status.html), ~~57,55,53,50,45~~, 36 bytes
```
x;y;f(a){for(x=y=1;y-a-x;y+=x=y-x);}
```
Naive approach based on calculating all previous Fibonacci numbers, breaking when we reach the input.
[Try it here](https://tio.run/##dczBCgIhGATgu08hG4GyGbkRBH/2JF1E1xJKw3VDWfbZzUu3nNvMB6PYXalSEmQwRNLF@ECSyIJDZpLVuRe1skRhLRvr1HPW42WK2vr944qsi/glrSMfbzVdEK55h7oa0m31zXU7QwZK4S8cW3BqwbkFvPk18J@EMc7B4QOgtXwB)
Edit: Thanks for Neil, golfing ~~2~~ 5 bytes.
Edit2: Thanks Dominic van Essen for golfing an other 5 bytes.
Edit3: Thanks att for golfing 9 bytes.
[Answer]
# [Python 3](https://docs.python.org/3/), 41 bytes
```
f=lambda n,a=0,b=1:n-b and f(n,b,a+b)or a
```
[Try it online!](https://tio.run/##xVBBboQwDLzzCt8A1SvhBBKyUvqRtocAQYvaZhGkUlvE26mD2jc0h2Q89owdz1/xdg/yOEb75t67wUFAZyvsLF3DpQMXBhiLgB26h668L@CO6Ne4goVCIEiEBqFFIEaCmKiZSZRhruZASM5IrREUVQimZUSN4Vs0LedralmmtGIRVaZW/GhNzIlWNVxWK6m4gW4qkUoEScOOZBQr2Zl0S1Rm/nP2ffRDmitp/320Mutvvn/1S5oof/4Quu5zhBORzMts5GVG9DAF@J7m4twqwt8/ymsGfNKexyKWZzAvU4jFmG9xh8sjbOsO22@TJ2/t@rKz7fED "Python 3 – Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), ~~29~~ ~~28~~ ~~27~~ 24 bytes
*The footer uses [@Noodle9's checker code](https://codegolf.stackexchange.com/a/247843/36398)*.
*1 byte saved thanks to [@Chris](https://codegolf.stackexchange.com/users/58834/chris)!*
*3 more bytes off thanks to [Albert.Lang](https://codegolf.stackexchange.com/users/101374/albert-lang)!*
Function that returns an integer-valued `float`. It fails for large inputs due to floating-point inaccuracies.
```
lambda n:~n*(1-5**.5)//2
```
[Try it online!](https://tio.run/##ZY1BDoIwEEXXcorZ0WJRWzQmJPUiyAJhEKLWhtYEJXh1rFVXzupN5s9/@m6bq0qmWu6nc3E5VAWo9KkiwuNNFC02dLkUk0VjjcwES/IAe42lxUpmnIk8qK8d9NAq6Ap1RCIYX61oGsx@sUWhNaqK@Ios5jkNZp7/DvMvCRcpGyxP2IEEEu5vYrsuQwaeeBJSL7UM39pHqz8VDH5Kpwc3xn3XxFK/6K5VltThYEeIdzCYEYavJEMpTT662ukF)
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 17 bytes
```
Round[2#/++√5]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2b7Pyi/NC8l2khZX1v7Uccs01i1/4GlmaklDgFFmXkl0cq6dmkOyrFqDlpumUn5eYnJyZl1wcmJeXVBiXnpqdHGOkYGsf8B "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 31 bytes
```
[int]("$args"/1.61803398874989)
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/PzozryRWQ0klsSi9WEnfUM/M0MLA2NjSwsLcxNLCUvP///9GxsYA "PowerShell – Try It Online")
The ratio of two adjacent numbers in the Fibonacci series rapidly approaches ((1 + sqrt(5)) / 2). So if N is divided by ((1 + sqrt(5)) / 2) and then rounded, the resultant number will be the previous Fibonacci number...
at least according to [this article.](https://www.geeksforgeeks.org/find-the-previous-fibonacci-number/#:%7E:text=Approach%3A%20The%20ratio%20of%20two,be%20the%20previous%20Fibonacci%20number.)
-16 thanks [mazzy](https://codegolf.stackexchange.com/users/80745/mazzy)
[Answer]
# [Haskell](https://www.haskell.org/), ~~38~~ 37 bytes
This works for an aribrary size of inputs. We iterate through the Fibonacci sequence until we find some number `x`, that is larger than half the input `n`. This is works because the previous fibonacci number is roughly `0.618*n`.
The Fibonacci list `f` was borrowed from [R. Martinho Fernandes](https://codegolf.stackexchange.com/questions/85/fibonacci-function-or-sequence#comment110_89).
```
g n=[x|x<-f,2*x>=n]!!0
f=0:scanl(+)1f
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P10hzza6oqbCRjdNx0irws42L1ZR0YArzdbAqjg5MS9HQ1vTMO1/bmJmnoKtQkFRZl6JgopCbmKBQrpCtJGOsY6pjoWOoXHsfwA "Haskell – Try It Online")
[Answer]
# JavaScript, Node.js, 32 bytes
*-1 thanks to Arnauld*
```
n=>(y=1,f=x=>y-n?f(y,y+=x):x)(0)
```
**Explanation:**
This is a recursive solution, based off one of the two most common recursive fibonacci algorithms, which involves a function `f(x, y) = f(y, x + y)` that stops at some point. With this function, `x` is always a fibonacci number, and `y` is always the fibonacci number after it, so once `y` is the fibonacci number we were given as input, we know `x` is the one before it.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 4 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
```
ÅF¨θ
```
[Try it online](https://tio.run/##yy9OTMpM/f//cKvboRXndvz/b2gAAA) or [verify some more test cases](https://tio.run/##yy9OTMpM/R/ic7jncGtaWaW9ksKjtkkKSvaV/w@3uh1acW7Hf53/AA).
`¨θ` could be a lot of different alternatives, like `Á¤` or ``\`.
**Explanation:**
```
ÅF    # Push a list of Fibonacci numbers lower than or equal to the (implicit) input
  ¨   # Remove the last one (the input)
   θ  # Keep the next last one
      # (after which it is output implicitly as result)
```
[Answer]
# [MathGolf](https://github.com/maxbergmark/mathgolf/blob/master/math_golf.txt), ~~6~~ 4 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py)
```
)φ/i
```
-2 bytes porting [*@emanresuA*'s Vyxal answer](https://codegolf.stackexchange.com/a/247842/52210), which is in turn a port of [*@Unmitigated*'s JavaScript answer](https://codegolf.stackexchange.com/a/247840/52210).
[Try it online.](https://tio.run/##y00syUjPz0n7/1/zfJt@5v//RlzGXKZcFlyGxlxGhlzGJlymQJ4ll6GJCQA)
**Original 6 [bytes](https://github.com/maxbergmark/mathgolf/blob/master/code_page.py) answer:**
```
╒fg<┤Þ
```
[Try it online.](https://tio.run/##y00syUjPz0n7///R1Elp6TaPpiw5PO//fyMuYy5TLgsuQ2MuI0MuYxMuUyDPksvQxAQA)
`g<` could alternatively also be `á>`: [try it online](https://tio.run/##y00syUjPz0n7///R1ElphxfaPZqy5PC8//@NuIy5TLksuAyNuYwMuYxNuEyBPEsuQxMTAA).
**Explanation:**
```
)      # Increase the (implicit) input-integer by 1
 φ/    # Divide it by the golden ratio 1.618033988749895
   i   # Truncate it to an integer
       # (the +1 and truncate act as a round builtin here, which MathGolf lacks)
       # (after which the entire stack is output implicitly as result)
```
```
╒      # Push a list in the range [1, (implicit) input-integer]
 f     # Get the 0-based n'th Fibonacci number for each value in this list
  g    # Filter it by:
   <   #  Where it's smaller than the (implicit) input-integer
    ┤  # Extract the trailing value
     Þ # Discard the list from the stack, keeping just that value
       # (after which the entire stack is output implicitly)
```
[Answer]
### [Python 3](https://docs.python.org/3/), ~~50 bytes~~ 48 bytes
```
def f(n,a=0,b=1):
 while b<n:a,b=b,a+b
 return a
```
[Try it online!](https://tio.run/##ZY1NbsMgEEb3nGJ2xgqJDLZUKSq9iOsFtofaakUQECWN5bMTTNNsMqtv/t6zv2E6mTrGETVoapiSFeslL48ELtP8g9C/m6NKo56pXU/AYTg7AyoG9MHLVrC6I3i1OAQcZcuZ6Ig@ObjCbMAp84VUMF5VG/D/7KCsRTPSjGj3vCsJ5Pyy2D2SSCfDhMM3OpBAi8@zeGuGgkFOvC7KLA0MN@1ttn8I9lRu@lQ@fWsaytxYN5tAdbGEFfYfsPgVloekRSl9tyZs5E0T7w "Python 3 – Try It Online")
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), 35 bytes
```
1+0.
N+M:-nth1(M,_,_),X is N-M,M+X.
```
[Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/31DbQI/LT9vXSjevJMNQw1cnXideUydCIbNYwU/XV8dXO0Lvv5WugrGJtq@OQkFRZl6Jhq@m3n8A "Prolog (SWI) – Try It Online")
-9 bytes thanks to Jo King
Of course, it's shorter to just use floating point:
# [Prolog (SWI)](http://www.swi-prolog.org), 31 bytes
```
N/M:-M is round(2*N/(1+5^0.5)).
```
[Try it online!](https://tio.run/##KyjKz8lP1y0uz/z/30/f10rXVyGzWKEovzQvRcNIy09fw1DbNM5Az1RTU@@/la6CsYm@r45CQVFmXomGL1AIAA "Prolog (SWI) – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 26 bytes
```
.+
$*
(\2?(\1)|1)+1
$1$2
1
```
[Try it online!](https://tio.run/##K0otycxL/K@q4Z7wX0@bS0WLSyPGyF4jxlCzxlBT25BLxVDFiMvw/38LLmMTLkMTEwA "Retina 0.8.2 – Try It Online") Link includes test cases. Explanation: Loosely based on @MartinEnder's Retina answer to [Am I a Fibonacci Number?](https://codegolf.stackexchange.com/q/126373).
```
.+
$*
```
Convert to unary.
```
(\2?(\1)|1)+1
```
Match as many Fibonacci numbers as possible. The first iteration only matches the leading `1` while subsequent iterations match iteration of the loop matches the penultimate Fibonacci number (if any), then the previous Fibonacci number, while saving it as the next penultimate Fibonacci number. The match actually sums the Fibonacci sequence, resulting in a sequence one less than the Fibonacci sequence, so a final `1` needs to be matched.
```
$1$2
```
Because the match is summing the sequence, the final capture of the sequence `$1` is actually the Fibonacci number before the one we want, so we need to add on the penultimate matched Fibonacci number `$2`.
```
1
```
Convert to decimal.
[Answer]
# [PARI/GP](https://pari.math.u-bordeaux.fr), 16 bytes
```
n->n*2\/(1+5^.5)
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m728ILEoMz69YMHiNAXbpaUlaboWG_J07fK0jGL0NQy1TeP0TDUhwjfN0_KLNDIVbBWMdBQMDQx0FPKA7LTMpPy8xOTkTI1MTWuFgqLMvBKNPAUlBV07IJGmkaepCdW-YAGEBgA)
Port of [Unmitigated's JavaScript answer](https://codegolf.stackexchange.com/a/247840/9288). `a\/b` is a short way to write `round(a/b)`.
PARI/GP's floating point number is 128-bit by default. This gives the correct result until the 184th Fibonacci number (`127127879743834334146972278486287885163`).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
‘:Øp
```
Add 1 to the input and integer-divide by the golden ratio.
[Try it online!](https://tio.run/##y0rNyan8//9RwwyrwzMK/v//b2wCAA "Jelly – Try It Online")
[Answer]
# [Husk](https://github.com/barbuz/Husk), 5 bytes
```
→←xİf
```
[Try it online!](https://tio.run/##yygtzv7//1HbpEdtEyqObEj7//@/kSEA "Husk – Try It Online")
Makes use of the built-in list of Fibonacci numbers.
### Explanation
```
→←xİf
   İf  Take the list of Fibonacci numbers
  x    Split it on occurrences of the input
 ←     Get the first sub-list
→      Get the last element of that
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 10 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
Çâ'Ç,¼)í"─
```
[Run and debug it](https://staxlang.xyz/#p=808327802cac29a122c4&i=2%0A3%0A5%0A8%0A19134702400093278081449423917&a=1&m=2)
### Approach
* Start with an infinite Fibonacci generator
* Keep values while they are less than the input, resulting in array e.g. `[1, 1, 2, 3, 5]`.
* Extract last element.
[Answer]
# [K (ngn/k)](https://codeberg.org/ngn/k), ~~12~~ 11 bytes
```
--2!(1-%5)*
```
[Try it online!](https://ngn.codeberg.page/k/#eJxNjU1OwzAYRPc+xYegUgK4xn+xYx+DZVXR1Nht1NYucYJSoXJ2LLHJavRGTzPBYMweKopXsn5GaDQ/T5vb72ACAMx2l0622oWuP9vZ3uxQb+8o9Pt3/zX56LxhwEGCBsqBUeACZKEWqBDAOAeuFDT0DVqtgMpWAZNagKCaQqMaWe42izVLXzH9WBRbhF6qpRBgQTVCBB3H8ZoNIS59+kM6h3UeO3fyszt28eDXLl1IsfPYp5gJE0pzSa6D/+7TlHEZS7Fzrsdxuuz9UAQtVPP4H+gPmTxTfA==)
Applies @Albert.Lang's approach from [this comment](https://codegolf.stackexchange.com/questions/247835/previous-fibonacci-number?answertab=scoredesc#comment554398_247844).
* `(1-%5)*` calculate 1 minus the square root of 5 (i.e. `-1.2360679774997898`) and multiply it by the (implicit) input
* `-2!` integer divide by 2 (rounding towards 0, e.g. `-8!-7` returns `-1`)
* `-` negate (and implicitly return)
[Answer]
# [APL(Dyalog Unicode)](https://dyalog.com), 17 bytes [SBCS](https://github.com/abrudz/SBCS)
```
{⌊.5+⍵÷.5×1+5*.5}
```
[Try it on APLgolf!](https://razetime.github.io/APLgolf/?h=AwA&c=q37U06Vnqv2od@vh7Xqmh6cbaptq6ZnWAgA&f=e9Q39VHbhDQFQwtjM2NDQ0sDY65HUCELSwA&i=AwA&r=tryapl&l=apl-dyalog&m=dfn&n=f)
5
[Answer]
# [Pip](https://github.com/dloscutoff/pip), 10 bytes
```
Ua*DRT5//2
```
[Attempt This Online!](https://ato.pxeger.com/run?1=m724ILNgebSSbkWBUuyCpaUlaboWq0ITtVyCQkz19Y0gAlDxm2rRStGGCkYKxgqmChYKhsYKRoYKxiYKpkCepYKhiYmCkbFxLNwYAA)
[Answer]
# [Fig](https://github.com/Seggan/Fig), \$5\log\_{256}(96)\approx\$ 4.116 bytes
```
_\mG}
```
[Try it online!](https://fig.fly.dev/#WyJfXFxtR30iLCI0MTgxIl0=)
No round builtins, so I use the old increment and floor trick.
```
_\mG}
    } # The input number incremented
 \    # Divided by
  mG  # The golden ratio
_     # Floor
```
[Answer]
# [Go](https://go.dev), 59 bytes
```
import."math"
func f(n float64)float64{return Round(n/Phi)}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NY9JDsIwDEX3OYXVVSOFoRNtQdwBsUUIhSEQ0ToopKuqR-AEbCokDsFRuA0ulI39_azv4f44mvZ1kbuzPB6glBqZLi_GuqGnSuc9K6cG2Xv2Z6V0J4-pCnegfARVGOkmMe9zbQ-usghLU-Hex9HipHnTj7h9Td0Cn9dM6e0VpnNYrf_WUEAkIBGQCQhIhQGBmEiHcmIxFWFEnShNBUyCsYA8IxUkOcUwyeKGKWNhI3A6txLpnW5LzRZWoyvQR9HdzDlrWH9U2_7yBw)
wow built-in constants
### Calculated version, 72 bytes
```
import."math"
func f(n float64)float64{return Round(2*n/(1+Pow(5,0.5)))}
```
[Attempt This Online!](https://ato.pxeger.com/run?1=NY9BTsMwEEX3PsUoKxuGUjtxm1TqnmXVLULIlLpENOPKOGIR5QicgE1UiUNwFG7DBNLNzJ830v8zn-dDGL5PbvfqDntoXE2ibk4hplnmm5R9tcnflD93F9a49JIJ39IOvCTwx-DSolBT7-I-tZFgG1p6luaKbqW-3oR3aXE-s0qpfvL7-HMY06TqhK-f3mC1hvuHi49ByBEsQomgWRnNoGAyoopZwYPJeZMvlwgLPUeoSlbaVlyNLYte-BDhEWm1jo74tzGlE5tYUzqSJBwfUEr0YjpqGP77Lw)
[Answer]
# m68k assembly (GNU), 16 bytes
```
70 00 72 01 d0 81 c1 41 b2 af 00 04 66 f6 4e 75
```
Or in assembly:
```
begin:
    moveq.l #0, %d0;
    moveq.l #1, %d1;
loop:
    add.l %d1, %d0;
    exg.l %d0, %d1;
    cmp.l 4(%sp), %d1;
    bne loop;
    rts;
```
Works with both the Linux and the SysV calling conventions (parameters on stack, return in %d0, %d0-%d1 are scratch registers).
The c function definition is:
```
unsigned long prev_fibonacci(unsigned long num);
```
All calculations are done in 32 bit mode. 16bit is the same size, only faster.
Code execution takes 22 cycles plus 46 cycles per loop iteration. (On a 68000 w/ a 16bit bus and no waitstates)
[Answer]
# x86-64 machine code, 10 bytes
Expects input in `edx` and outputs to `eax`.
```
b8 dd bc 1b cf f7 f0 d1 e8 c3 
```
[Try it online!](https://tio.run/##ZVJhb5swEP3OrzgxIUHibLBVWtWUTdHGh0ptEtF23bROCAwkSNggIGmiLn999I6QEDIUXex3z@/d@cxHC87r@l0ieboKI7guqzCR1fvlF6WPZf9BaRKcY0UiF2fYtvwghC8JVVaofOlVUPgvXh7HXrCtovK3Zf4BG17NTXDJwNyEIcWAU7QCijymGH9uotlwLIpRw@efdmNFWWdJCAMURe28KlBw@nh7iwm0BIR1@pcGvCqAH22KqFr7KTII8EuhNwv6VJGtIQo3DDQLniWoXYb7aQraxzOU@BoWFvmbfuYKVLsQKuh7M@M00eDSYO3qWHqPhIoqMrCYvajR1ot6q0Iee9jt@xR@InW6iUOfp/eBU8h1uhQGFtY6d2cPnutMvsPf/frJvXlwDhvnp/ONwd1k7s3dmx@TJkG7yXQ2/XU3e7zHm8cflkM2IhI833YtsP6EyfBQOJW5TBZLLMhix07T7KUPVCJvD8RZAc3wEtscQ3J9cYFxODx02JLxNGqMzwTJqMMa26F9ot0dphdCeaOj5/iYq1hXKaWFxhVoIdACtPJZ4lCIzug4IzcGeuPZyBvwFVSV5jcYgOO6MBiorfKuNz8TR1fX/3ic@ouyHj3h66pHAh@jjd5R@gY)
## Explanation
Disassembly:
```
b8 dd bc 1b cf          mov    eax,0xcf1bbcdd
f7 f0                   div    eax
d1 e8                   shr    eax,1
c3                      ret
```
The function approximates \$\operatorname{round}(\frac{n}{\phi})=\lfloor\frac{n+\frac{\phi}{2}}{\phi}\rfloor=\lfloor\frac{1}{2}\cdot\frac{2^{32}n+2^{31}\phi}{2^{31}\phi}\rfloor\$, where \$\phi=\frac{1+\sqrt{5}}{2}\$. \$2^{31}\phi\approx3474701533\$, which fits nicely into a 32-bit integer as `0xcf1bbcdd`. Since `div r32` works on `edx:eax`, `n` can be loaded into `edx` and `0xcf1bbcdd` can be loaded into `eax` to create the numerator of the fraction, while also having `eax` as the denominator of the fraction after `div eax`. Afterwards, all that is left is to divide by two, which is handled by `shr eax, 1`.
[Answer]
# [rSNBATWPL](https://github.com/Radvylf/rSNBATWPL), 32 bytes
```
x~for{t=1;x>t;f=b}{b=t;t=f+t}$-1
```
[Try It Online!](https://dso.surge.sh/#@WyJyYWlzaW4tYmF0d2FmZmxlIixudWxsLCJnPXh+Zm9ye3Q9MTt4PnQ7Zj1ifXtiPXQ7dD1mK3R9JC0xOyIsImckMTMiLCIiLCIiXQ==)
Port of R answer.
]