g | x | w | all
Bytes Lang Time Link
051AWK241125T212440Zxrs
153Regex ECMAScript241011T010213ZDeadcode
007Uiua241008T014226Znoodle p
003Vyxal 3241008T135247Zpacman25
041Python 3.8 prerelease241007T215348Zaeh5040
012x8664 assembly220526T030603ZChris
024C gcc230715T183638ZHunaphu
010x8664 machine code230716T012439Zengineer
016m68k assembly GNU230715T201031ZSaladin
004Thunno 2230715T164409ZThe Thon
043Scala230418T061335Z138 Aspe
017Rattle220531T145049Zd01
040Raku221130T155800ZMark Ree
014J221111T082039Zsouth
017><>221111T073708ZEmigna
nan221013T152436Zbigyihsu
nanFig220924T190119ZSeggan
035Prolog SWI220901T175739ZnaffetS
013TIBASIC220901T193455Zabsolute
029Ruby220901T133415ZG B
022Desmos220525T230933ZAiden Ch
045Brev220622T140630ZSandra
094Brainfuck220622T132455ZMennoK
093BitCycle u220617T201825ZNilster
010Pip220612T200609ZnaffetS
017APLDyalog Unicode220612T082051ZKamila S
011K ngn/k220611T143230Zcoltim
022K ngn/k220602T135418Zoeuf
010Stax220531T162348Zrecursiv
006Husk220525T225334ZDominic
006Vyxal220525T201814ZnaffetS
005Husk220527T153457ZLeo
048Python 3220526T214336Zaxolotl
020R220525T223316ZDominic
017JavaScript220525T202719ZUnmitiga
027C gcc220526T234420Zc--
004Jelly220526T232411ZLuis Men
037Haskell220526T213852Zflawr
5714Haskell220526T160142Zstaletid
031PowerShell220526T181420Zanother
024Python 3220525T213755ZLuis Men
016PARI/GP220526T040207Zalephalp
004MathGolf220525T221022ZKevin Cr
036Cgcc220525T222718ZLala5th
014Factor + math.unicode220525T202436Zchunes
026Retina 0.8.2220525T225556ZNeil
017Wolfram Language Mathematica220525T224643Zatt
024Charcoal220525T223524ZNeil
004Vyxal220525T211849Zemanresu
00405AB1E220525T215731ZKevin Cr
031rSNBATWPL220525T215716Zrydwolf
041Python 3220525T212013ZNoodle9
032rSNBATWPL220525T203354ZnaffetS
032JavaScript220525T200912Zrydwolf
nan220525T202325ZGiuseppe

AWK, 51 bytes

{(n=$1/(((1+sqrt(5))/2)))-int(n)>=.5&&n++}$0=int(n)

To test:

awk '{(n=$1/(((1+sqrt(5))/2)))-int(n)>=.5&&n++}$0=int(n)' <<< 1597

{(n=$1/(((1+sqrt(5))/2)))  # magic algorithm
-int(n)>=.5&&n++}          # handle rounding
$0=int(n)                  # set output

Regex (ECMAScript), 153 bytes

(?=(x*).*(?=x{4}(x{5}(\1{5}))(?=\2*$)\3+$)(|x{4})(?=xx(x*)\5)\4(x(x*))(?=(\6*)\7+$)(?=\6*$\8)\6*(?=x\1\7+$)(x*)(\9x?)|)((\5\10)(\9\10\12?)?|x{5}|xx?x?)\B

Try it online!

Takes its input in unary, as a string of x characters whose length represents the number. Returns its output as the length of the match.

This is based on Am I a Fibonacci Number? (161 bytes), with some modifications that take advantage of the difference between that problem and this one.

                           # tail = N = input number; no need for an anchor, because all
                           # Fibonacci inputs except for 1 will return a match
(?=
    (x*)                   # \1+1 = potential number for which 5*(\1+1)^2 ± 4 is a
                           # perfect square; this is true iff \1+1 is a Fibonacci number,
                           # which we shall call F_n. Outside the surrounding lookahead
                           # block, \1+1 is guaranteed to be the largest number for which
                           # this is true such that \1 + 5*(\1+1)^2 + 4 <= N.
    .*
    (?=                    # tail = (\1+1) * (\1+1) * 5 + 4
        x{4}
        (                  # \2 = (\1+1) * 5
            x{5}
            (\1{5})        # \3 = \1 * 5
        )
        (?=\2*$)
        \3+$
    )
    (|x{4})                # \4 = parity - determined by whether the index of Fibonacci
                           #               number \1+1 is odd or even;
    (?=
        xx                 # tail = arithmetic mean of (\1+1) * (\1+1) * 5 and \6 * \6
                           #      = ((F_n * F_n * 5) + (L_n * L_n)) / 2 = L_{2n}
        (x*)\5             # \5 = floor(tail / 2) = floor(L_{2n} / 2)
    )
    \4
    # require that the current tail is a perfect square
    (x(x*))                # \6 = potential square root, which will be the square root
                           #      after the following two lookaheads; \7 = \6-1
    (?=(\6*)\7+$)          # \8 = must be zero for \6 to be a valid square root
    (?=\6*$\8)
    # \6 is now the Lucas number L_n corresponding to the Fibonacci number F_n.
    \6*
    (?=x\1\7+$)            # tail = F_{2n} = L_n * F_n = \6 * (\1+1), where \6 is larger
    (x*)(\9x?)             # \9 = floor(tail / 2);
                           # \10 = ceil(tail / 2); the remainder tail % 2 will always be
                           #       the same as the remainder discarded by \5, because
                           #       F_{2n} is odd iff L_{2n} is odd, thus this ceil()
                           #       can complement the floor() of \5 when adding \5 + \10
|                          # Allow everything above to be skipped, resulting in all
                           # capture groups being unset.
)
(
    # Note that if the above was skipped using the empty alternative in the lookahead,
    # the following will evaluate to 0. This relies on ECMAScript NPCG behavior.
    (\5\10)                # \12  = F_{2n+1} = (L_{2n} + F_{2n})/2 = \5 + \10; head=\12
    (
        \9\10              # head = F_{2n+2} = F_{2n}   + F_{2n+1}
                           #                 = \9+\10   +   \12
        \12?               # head = F_{2n+3} = F_{2n+2} + F_{2n+1}    (optionally)
                           #                 = head     +   \12;
                           # This is needed only for an input of N = 21, which is an
                           # exception because 2^2*5+4 = 24 > 21, thus the algorithm
                           # chooses 1^2*5+4 = 9 as its square instead. This won't break
                           # any subsequent Fibonacci inputs, because executing this
                           # optional will in those cases set tail = 0, breaking the
                           # final assertion.
    )?                     # Do the above optionally
|
    x{5}|xx?x?             # The cases 2→1, 3→2, 5→3, and 8→5 cannot be handled by our
                           # main algorithm, so match them here.
)
\B                         # Assert head ≠ 0 and tail ≠ 0

Regex (ECMAScript), 162 bytes

\B(?=(x*).*(?=x{4}(x{5}(\1{5}))(?=\2*$)\3+$)(|x{4})(?=xx(x*)\5)\4(x(x*))(?=(\6*)\7+$)(?=\6*$\8)\6*(?=x\1\7+$)(x*)(\9x?)|)(\9\10(\5\10)\12?|x{21}|x{8}|x{5}|xx?x?)$

Try it online!

This is an exact clone of Am I a Fibonacci Number? (161 bytes) with the ^ anchor replaced with \B, which is a shorthand for (?!^|$). So the regex engine goes forward one character at a time looking for a match, thus matching the largest Fibonacci number less than the input. As such this is much slower than the 153 byte version.

(What we'd really like is (?!^) instead of \B, so we could return an output of \$0\$ from an input of \$1\$, but that would take 3 more bytes, and the problem doesn't require handling \$1\$.)

Uiua, 7 bytes

⍢⤙+⋅≠.1

Try it: Uiua pad

Starting with two ones, repeatedly add them while bringing the second number to the top until the second number is equal to the input. Then, the top number is the previous fibonacci.

Alternatively, using the method of dividing by the golden ratio:

Uiua, 8 bytes

⁅÷÷2+1√5

Try it: Uiua pad

Uiua is read right to left and stack-based, so written with more traditional infix this is equivalent to:

⁅(x÷((1+√5)÷2))

(where means round to the nearest integer)

Vyxal 3, 3 bytes

kgṠ

Vyxal It Online!

integer divide by the golden ratio.

Python 3.8 (pre-release), 41 bytes

A different method. Impractically slow for large values without caching. For n between two Fibonaccis it returns the lower one.

g=lambda n:n and[a:=g(n-1),n-1][g(a)+a<n]

Try it online!

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!

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 48th Fibonacci number, 4807526976. This does not fit in a 32-bit integer but its result does so and it is not the same as any previous number modulo 2^32 so the math works out.

It can be expanded to work properly 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.

C (gcc), 26 24 bytes

-4 thanks to c--.

This uses int and overflows at the 46th fib (first exceeding \$2^{31}\$) but

p(n){n=round(n*2/(1+sqrt(5)));} breaks at 43 and is longer.

p(n){n=n*.618033989+.5;}

Try it online!

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!

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.

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)

Thunno 2, 4 bytes

kG/V

Try it online!

Explanation

      # Implicit input...
  /   # ...divided by...
kG    # ...phi...
   V  # ...then rounded
      # Implicit output

Scala, 43 bytes

Try it online!

def f(n:Int)=((n*math.sqrt(5)-n+1)/2).toInt

Rattle, 17 bytes

|r`=+s[$+~[\gq]]0

Try it Online!

Explanation

|             take input
 r`           save input as special arg
   =          set top of stack to 0
    +         increment
     s        save value of 1 to storage
      [...]0  infinite loop

 $            swap top of stack with value in storage
  +~          increment top of stack by value in storage
    [\...]    if the top of the stack is equal to the special arg...
      g       get the value in storage (i.e. the previous Fibonacci value)
       q      quit and print implicitly

Raku, 40 bytes

sub p(\n,\a=0,\b=1){n==b??a!!p(n,b,a+b)}

Try it online!

J, 12 14 bytes

1.61803<.@%~>:

Pretty self-explanatory.

Attempt This Online!

1.61803<.@%~>:
            >:  NB. increment input
1.61803         NB. golden ratio
          %~    NB. flip arg order and divide
       <.@      NB. then floor the result

I saw 1.618 might be too inaccurate. -:>:%:5 results in 1.61803, so I added the extra digits.

><>, 17 bytes

01\~n;
=?\:@+:{:}

Try it online

Explanation

Starts at 0,1.
Calculates the next Fibonacci number until we reach the input.
Prints the second newest.

Go, 59 bytes

import."math"
func f(n float64)float64{return Round(n/Phi)}

Attempt This Online!

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!

Fig, \$5\log_{256}(96)\approx\$ 4.116 bytes

_\mG}

Try it online!

No round builtins, so I use the old increment and floor trick.

_\mG}
    } # The input number incremented
 \    # Divided by
  mG  # The golden ratio
_     # Floor

Prolog (SWI), 35 bytes

1+0.
N+M:-nth1(M,_,_),X is N-M,M+X.

Try it online!

-9 bytes thanks to Jo King

Of course, it's shorter to just use floating point:

Prolog (SWI), 31 bytes

N/M:-M is round(2*N/(1+5^0.5)).

Try it online!

TI-BASIC, 13 bytes

round(2Ans(1+√(5))⁻¹,0

Hexdump:
(Token hex-values found here.)

12 32 72 10 31 70 BC 35 11 11 0C 2B 30 | round(2Ans(1+√(5))⁻¹,0

Takes input in Ans and prints the requested output in the challenge.

Explanation:

round(2Ans(1+√(5))⁻¹,0           ; full program

           1+√(5)                ; phi * 2
          (      )⁻¹             ; 1 / (phi * 2)
       Ans                       ; Ans / (phi * 2)
      2                          ; Ans / phi
round(              ,0           ; round to nearest integer

Note: TI-BASIC is a tokenized language. Character count does not equal byte count.

TI-BASIC only has decimal precision up to 14 decimals for calculations and 10 decimals for equivalence.

Byte count is determined via the following steps:

  1. Find the program's size via MEM>Mem Mgmt/Del…>Prgm…
  2. Subtract the length of the program name
  3. Subtract the program header length, which is 9 bytes

Ruby, 29 bytes

->n{a=b=1;0while n>a=b+b=a;b}

Try it online!

Desmos, 25 22 bytes

-3 bytes thanks to @Steffan

pp-p~1
f(n)=round(n/p)

Port of some of the other answers.

Try It On Desmos!

Brev, 50 45 bytes

(define((p x y)n)(if(= n y)x((p y(+ x y))n)))

Example:

(map (p 0 1) '(34 13 55 2))
=> (21 8 34 1)

Brainfuck, 94 bytes

>>>>+<<<+[[-]<[->+>+<<]>>[-<<+>>]>>[->+>+<<]>>[-<<+>>]<<<[->>+<<]>[-<+>]>[-<+<<<->>>>]<<<<]>>

Input should be entered into the first address. Output is at the address pointed to when the program terminates.

Might add an explanation later.

BitCycle (-u), 93 bytes

Try it online!

    v    / <^ ~+AA/v
1v ~B B vC   v> ^/ <
v ~ ?\BB\v  ?= ~ !
1D~ D ^  +C >~
ADA~^   +  ^   B@

The program generates a Fibonacci number, doubles it, and compares it to the input. If it's greater than or equal to the input, it is halved and output, otherwise it's discarded and the next number is generated.

          the question mark [input] hits a splitter [\]. one bit is redirected while the rest of the bits move to top B  [input].
1v ~B     top D [2fib(n-1)], which starts with 2, is emptied to right A [2fib(n)] and left A [intermittent]. 
v ~ ?\B   bottom D [2fib(n-2)] empties to right A.
1D~       right A empties to top D and top B [2fib(n)].
ADA~      left A empties to bottom D [2fib(n-2)].
v    / <   *'top B' refers to BOTH B's; 'bottom B' refers to BOTH B's*
B B vC     if bottom B [input] isn't empty, it hits a splitter. one bit is redirected to D [intermittent] while the rest of the bits re-enter bottom B.
  BB\v     top B [2fib(n)] hits a splitter. one bit is redirected to top C [2fib(n)] while the rest re-enter top B.
D ^  +C    if bottom B is empty, top B hits another splitter. one bit is redirected to bottom C ["2fib(n) >= input"?].
^   +  ^   D will eventually empty to bottom B.
   ^ ~+AA/v   *'A' refers to BOTH A's
C   v> ^/ <   if bottom C ["2fib(n) >= input"?] isn't empty, it hits a switch. the bits are redirected to B [terminator]
   ?= ~ !     if bottom C is empty, top C [2fib(n)] hits a switch. the bits are redirected into the question mark, destroying them.
 C >~         if bottom C isn't empty, top C empties to A [fib(n)]
      B@      A hits 2 splitters. one bit is redirected away, and another is redirected into the exclamation mark [output]. the rest of the bits re-enter A.
              B empties into the at-sign, which terminates the program.

Pip, 10 bytes

Ua*DRT5//2

Attempt This Online!

APL(Dyalog Unicode), 17 bytes SBCS

{⌊.5+⍵÷.5×1+5*.5}

Try it on APLgolf!

5

K (ngn/k), 12 11 bytes

--2!(1-%5)*

Try it online!

Applies @Albert.Lang's approach from this comment.

K (ngn/k), 21 22 bytes

{_x%1.618033988749895}

Try it online!

Increased 1 byte to round the number.

Stax, 10 bytes

Çâ'Ç,¼)í"─

Run and debug it

Approach

Husk, 6 bytes

i*½←√5

Try it online!

Same strategy as my R answer (and also those of Luis Mendo and unmitigated).

(Husk has a fibonacci sequence built-in, but using it here seems to come-out longer at 7 bytes: S!o←€İf).

Update: proven wrong by Leo

Vyxal, 6 bytes

ÞFḟ‹∆f

Try it Online!

Husk, 5 bytes

→←xİf

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

Python 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!

R, 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!

The ratio between consecutive fibonacci numbers famously converges towards the golden ratio phi, 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 and unmitigated)

JavaScript, 21 17 bytes

n=>n*5**.5-n+1>>1

Try it online!

-4 bytes thanks to att.

C (gcc), 27 bytes

f(a){a=2*a/(1+sqrt(5))+.5;}

Port of Unmitigated's JavaScript answer.

Try it online!

Jelly, 4 bytes

‘:Øp

Add 1 to the input and integer-divide by the golden ratio.

Try it online!

Haskell, 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.

g n=[x|x<-f,2*x>=n]!!0
f=0:scanl(+)1f

Try it online!

Haskell, 57 bytes (or 14 bytes)

Complete solution which handles arbitrarily large input:

f n=(x!!).flip(-)1.length.fst.span(<n)$x
x=scanl(+)0(1:x)

Explanation:

  1. Let x be a an infinite list of fibonacci numbers ( x = scanl (+) 0 (1:x) ).

  2. Partition list into a tuple ([Int], [Int]), the leftmost portion being all numbers < than the input.

  3. Take the first portion with fst.

  4. Subtract 1 from the length of that list.

  5. Extract (!!) the number with the resultant (idx--) index from the infinite list.

Simple solution:

round.(/0.618)

PowerShell, 31 bytes

[int]("$args"/1.61803398874989)

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.

-16 thanks mazzy

Python 3, 29 28 27 24 bytes

The footer uses @Noodle9's checker code.

1 byte saved thanks to @Chris!

3 more bytes off thanks to 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!

PARI/GP, 16 bytes

n->n*2\/(1+5^.5)

Attempt This Online!

Port of Unmitigated's JavaScript answer. 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).

MathGolf, 6 4 bytes

)φ/i

-2 bytes porting @emanresuA's Vyxal answer, which is in turn a port of @Unmitigated's JavaScript answer.

Try it online.

Original 6 bytes answer:

╒fg<┤Þ

Try it online.

g< could alternatively also be á>: try it online.

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)

C(gcc), 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

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.

Factor + math.unicode, 21 19 18 14 bytes

[ φ / round ]

Try it online!

-4 thanks to @DominicvanEssen!

Divide the input by the golden ratio and round the result.

Retina 0.8.2, 26 bytes

.+
$*
(\2?(\1)|1)+1
$1$2
1

Try it online! Link includes test cases. Explanation: Loosely based on @MartinEnder's Retina answer to Am I a Fibonacci Number?.

.+
$*

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.

Wolfram Language (Mathematica), 17 bytes

Round[2#/++√5]&

Try it online!

Charcoal, 24 bytes

NθF²⊞υιW‹⌈υθ⊞υΣ…⮌υ²I§υ±²

Try it online! Link is to verbose version of code. Explanation:

Nθ

Input the target.

F²⊞υι

Start with [0, 1].

W‹⌈υθ

Repeat until the target is reached.

⊞υΣ…⮌υ²

Generate the next Fibonacci number.

I§υ±²

Output the highest one less than the input.

Vyxal, 4 bytes

kg/ṙ

Try it Online!

Port of Unmitigated's JavaScript answer

  /  # Divide by...
kg   # Phi
   ṙ # Round

05AB1E, 4 bytes

ÅF¨θ

Try it online or verify some more test cases.

¨θ 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)

rSNBATWPL, 31 bytes

n~(y=1;x~cond{y!n}{{y=y+x}}$x)$

Try It Online!

Port of my JS answer:

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.

Python 3, 41 bytes

f=lambda n,a=0,b=1:n-b and f(n,b,a+b)or a

Try it online!

rSNBATWPL, 32 bytes

x~for{t=1;x>t;f=b}{b=t;t=f+t}$-1

Try It Online!

Port of R 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.

R, 27 bytes

\(x){while(x>T)T=F+(F=T);F}

Attempt This Online!

Similar to this answer, iterates through the Fibonacci sequence until T==x and returns F.