g | x | w | all
Bytes Lang Time Link
106Pure bash250622T063810ZF. Hauri
007Perl 5 p250622T053648ZXcali
005Juby250621T163003ZJordan
nan250621T001455ZRARE Kpo
001Thunno 2230607T075315ZThe Thon
nan230219T153625ZThe Thon
040Pascal230219T001743ZKai Burg
001Pyt230218T224010ZKip the
005Factor221003T210722Zchunes
006Kotlin221003T161754ZSeggan
nan221003T152305Zbigyihsu
001Vyxal221003T132604Zpacman25
100HODOR170403T213309Zcaird co
031NO!170402T004055Zcaird co
003MATL170330T175658ZSuever
015Rogex200121T045706Zlyxal
003W200120T230405Zuser8505
001Keg190915T051822Zuser8505
016SenseTalk180322T020429ZAllen Fi
007AWK170405T141908ZRobert B
048KoopaScript180318T153127ZJhynjhir
015Bash170423T033107ZGraviton
003Julia170330T180751ZUriel
004Attache180201T181009ZConor O&
1420OIL170331T192215ZL3viatha
003Aceto 1.0170410T102958ZL3viatha
003ARBLE171019T044922ZATaco
001Common Lisp171019T042214Zceilingc
009Groovy170525T200633ZMagic Oc
001APL170330T182137ZUriel
005Cheddar170330T185543ZConor O&
0048087 machine code170420T042319Zuser5434
007Perl 5170419T060713Zmsh210
nanBatch170409T080538Zstevefes
011Jelly170418T175047Zfireflam
001Convex170418T025157ZGamrCorp
079Fourier NonCompeting170417T182002ZBeta Dec
024PHP170417T221438Zdv02
057Axiom170417T135503Zuser5898
004Haskell170417T133618ZEnderper
006CGL CGL Golfing Language170414T202646Zuser5882
nanBrainFlak170331T002852ZWheat Wi
nansed170401T183558Zuser4180
025Python 2.7170409T071437ZKoishore
002Pyth170330T180429ZNoOneIsH
nanGNU sed170406T123649Zseshouma
008JavaScriptES7170402T045841ZMatthew
012REXX170405T121133Zidrougge
006Javascript ES6170330T175702Zfəˈnɛtɪk
012C170330T180615ZSteadybo
007Racket170402T044323Zrnso
012Bash + bc170402T043147ZChristop
011Emacs Lisp170402T042815ZChristop
002TIBasic TI84 Plus CE170331T021256Zpizzapan
091Retina170331T070455ZMartin E
056LOLCODE170330T203151ZDJMcMayh
007Elixir170331T194549Zadrianmp
006C#170331T055701Zadrianmp
010bc170331T124347ZMax Mikh
015Scala170331T083650ZStefan A
012OCaml170331T154420ZRedouane
001Noodel170331T151632Ztkellehe
024C++ lambda function170331T124644Zjdt
002TIBasic170331T123241ZTimtech
008Vim170330T182106ZDJMcMayh
029Java 7170331T083429Zpeech
008R170331T075520ZRudier
006dc170330T183810Zseshouma
007Excel VBA170331T015619ZTaylor R
467Taxi170330T193137ZErik the
002Brachylog170331T070400ZFatalize
011PHP170331T063108ZChristop
005Dyvil170331T052027ZClashsof
011Racket170331T042509Zassefama
nan170331T034509ZBrad Gil
003Scala170331T011440ZBrian Mc
001Actually170330T180140Zquintopi
005x86_64 Linux machine language170330T202529Zceilingc
004Haskell170330T202957Zflawr
001J170330T181227Zxenia
003Forth170330T201836Zmbomb007
013ZX Spectrum BASIC170330T201358ZNeil
3320JSFuck170330T185152Zpowelles
005yup170330T194534ZConor O&
005QBIC170330T194354Zsteenber
004Gol><>170330T193643ZErik the
030C170330T180725Zanna328p
006Bean170330T181432ZPatrick
002Japt170330T184240ZETHprodu
010Python 2170330T183212ZDennis
001Jelly170330T182825ZDennis
004Mathematica170330T175937ZMartin E
004Mathics170330T181908ZPavel
023Fortran 95170330T180932ZSteadybo
003Jellyfish170330T180926ZMartin E
012Python170330T175538Zxenia
003Quetzalcoatl170330T180106ZNoOneIsH
004MATLAB / Octave170330T180036ZSuever
006Java 8170330T175907Zxenia
004CJam170330T175905ZBusiness
00105AB1E170330T175839ZRiley
010Ruby170330T175705Zanna328p

Pure bash: 106

Without any fork!!

printf -vv %.6f ${1#-}
v=00000$((1000000000000/10#${v/.}))
printf %s%.5f\\n "${1//[^-]}" ${v::-6}.${v: -6}

Take a try:

Showing bc's results side by side, with my function's results.

#!/bin/bash

reciprocal() {
    printf -vv %.6f ${1#-}
    v=00000$((1000000000000/10#${v/.}))
    printf %s%.5f\\n "${1//[^-]}" ${v::-6}.${v: -6}
}

tests=( 0.5134  0.5  2  2.0  0.2  51.2  113.7  1.337
        -2.533  -244.1  -0.1  -5 )

for i in ${tests[@]};do
    reciprocVal=$(reciprocal $i)
    verifByBc=$(bc -l <<<"1/$i")
    printf '%12.4f -> %9.4f  (%9.4f)\n' $i \
         "$reciprocVal" "$verifByBc"
done
      0.5134 ->    1.9478  (   1.9478)
      0.5000 ->    2.0000  (   2.0000)
      2.0000 ->    0.5000  (   0.5000)
      2.0000 ->    0.5000  (   0.5000)
      0.2000 ->    5.0000  (   5.0000)
     51.2000 ->    0.0195  (   0.0195)
    113.7000 ->    0.0088  (   0.0088)
      1.3370 ->    0.7479  (   0.7479)
     -2.5330 ->   -0.3948  (  -0.3948)
   -244.1000 ->   -0.0041  (  -0.0041)
     -0.1000 ->  -10.0000  ( -10.0000)
     -5.0000 ->   -0.2000  (  -0.2000)

Try it online!

For fun: Over an array, but without loop: 293

Still pure , without any fork.

local a t p=printf\ -vt
$p '%.6f ' ${@#-}
a=($t)
a=(${a[@]/.})
local -ai i=("${a[@]/#/1000000000000/10#}")
$p '%020.0f ' ${i[@]}
a=($t)
$p '%%s.%s ' ${a[@]/#??????????????}
$p "$t" ${a[@]/%??????}
$p '%%s%.4f\n' ${t}
$p "$t" "${@//[^-]}"
a=($t)
$p '%%20.4f %9.4f\n' ${a[@]}
printf "$t" "${@}"

Take a try:

#!/bin/bash

reciprocal() { 
    local a t p=printf\ -vt
    $p '%.6f ' ${@#-}
    a=($t)
    a=(${a[@]/.})
    local -ai i=("${a[@]/#/1000000000000/10#}")
    $p '%020.0f ' ${i[@]}
    a=($t)
    $p '%%s.%s ' ${a[@]/#??????????????}
    $p "$t" ${a[@]/%??????}
    $p '%%s%.4f\n' ${t}
    $p "$t" "${@//[^-]}"
    a=($t)
    $p '%%20.4f %9.4f\n' ${a[@]}
    printf "$t" "${@}"
}

reciprocal 0.5134 0.5 2 2.0 0.2 51.2 113.7 1.337 \
           -2.533 -244.1 -0.1 -5
              0.5134    1.9478
              0.5000    2.0000
              2.0000    0.5000
              2.0000    0.5000
              0.2000    5.0000
             51.2000    0.0195
            113.7000    0.0088
              1.3370    0.7479
             -2.5330   -0.3948
           -244.1000   -0.0041
             -0.1000  -10.0000
             -5.0000   -0.2000

Try it online!

Without format printing: 227

Showing results only, we just have to skip last step.

p=printf\ -vt;$p %.6f\  ${@#-};a=($t);a=(${a[@]/.})
declare -ai i=(${a[@]/#/1000000000000/10#});$p %020.0f\  ${i[@]};a=($t)
$p %%s.%s\  ${a[@]/#??????????????};$p "$t" ${a[@]/%??????};$p %%s%.4f\\n ${t}
printf "$t" "${@//[^-]}"

Try it online!

Into a function 235

local a t p=printf\ -vt;$p %.6f\  ${@#-};a=($t);a=(${a[@]/.})
local -ai i=(${a[@]/#/1000000000000/10#});$p %020.0f\ ${i[@]};a=($t)
$p %%s.%s\  ${a[@]/#??????????????};$p "$t" ${a[@]/%??????};$p %%s%.4f\\n ${t}
printf "$t" "${@//[^-]}"

Take a try:

#!/bin/bash

reciprocal() {
    local a t p=printf\ -vt;$p %.6f\  ${@#-};a=($t);a=(${a[@]/.})
    local -ai i=(${a[@]/#/1000000000000/10#});$p %020.0f\ ${i[@]};a=($t)
    $p %%s.%s\  ${a[@]/#??????????????};$p "$t" ${a[@]/%??????}
    $p %%s%.4f\\n ${t};printf "$t" "${@//[^-]}"
}

reciprocal 0.5134  0.5  2  2.0  0.2  51.2  113.7 \
           1.337  -2.533  -244.1  -0.1  -5
1.9478
2.0000
0.5000
0.5000
5.0000
0.0195
0.0088
0.7479
-0.3948
-0.0041
-10.0000
-0.2000

Try it online!

Perl 5 -p, 7 bytes

$_**=-1

Try it online!

J-uby, 5 bytes

Returns a Float for Float inputs or a Rational for Integer or Rational inputs.

:/&1r

Attempt This Online!

awk

Taking negative-one power is much safer than 1 / n because a zero input would safely return inf instead of crashing with division-by-zero error.

echo '0.5134
0.5
2
2.0
0.2
51.2
113.7
1.337
-2.533
-244.1
-0.1
-5' | 

awk 'function __(_) { return _^-1 }'

0.5134  1.9478
0.5     2
2       0.5
2.0     0.5
0.2     5
51.2    0.0195312
113.7   0.00879507
1.337   0.747943
-2.533  -0.394789
-244.1  -0.00409668
-0.1    -10
-5      -0.2

Without wrapping it in a function, it's actually ultra short in awk :

awk '$1^=-1'

6 ASCII bytes.

Thunno 2, 1 byte

Attempt This Online!

Built-in.

Thunno 2, 8 bytes

ÆtÆCÆsÆT

Attempt This Online!

Uses the fact that: $$\tan(\arcsin(\cos(\arctan(x)))) \equiv {{1} \over {x}}$$

Thunno, \$ 1 \log_{256}(96) \approx \$ 0.82 bytes

o

Attempt This Online!

Built-in solution.

Pascal, 40 bytes

The built-in data type real provides an implementation-defined approximation.

function f(x:real):real;begin f:=1/x end

Pyt, 1 byte

Try it online!

Just another language with a built-in one-byte reciprocal function

Factor, 5 bytes

recip

Try it online!

Kotlin, 6 bytes

{1/it}

Attempt This Online!

Simple anonymous function.

Go, 34 bytes

func(a float64)float64{return 1/a}

Attempt This Online!

Vyxal, 1 byte

Ė

Try it Online!

HODOR, 100 bytes

Walder
Hodor?!
Hodor, Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor, Hodor,
HODOR!!
HODOR!!!

If you must know how it works, I'll tell you.

Explanation

Walder                                                                       Hodor hodor
Hodor?!                                                                     Hodor hodor hodor HODOR
Hodor, Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor, Hodor,        Hodor hodor hodor hodor hodor hodor
HODOR!!                                                                     Hodor hodor hodor hodor hodor
HODOR!!!                                                                    Hodor hodor (Hodor hodor hodor)

Walder - Start program

Hodor?! - Take input from STDIN

Hodor, Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor, Hodor, - Change accumulator value to it's reciprocal

HODOR!! - Output accumulator value as number

HODOR!!! - Kill Hodor (End the program)

NO!, 31 bytes

NO! has 6 valid tokens: NOno!? and commands are made up of NO with the number of O determining the command.

NOOOOO?no!NOOOOOOOOOOO
NOOOOOOOO?no

###More readable

NOOOOO?                 NOOOOO is the divide command and ? starts the arguments
       no!              no is 1 and ! separates the arguments            
          NOOOOOOOOOOO  This takes input from STDIN.

NOOOOOOOO?              This outputs the result of the       line
          no                                           first 

The equivalent pseudocode:

output divide 1, input

MATL, 3 bytes

l_^

Try it at MATL Online

Explanation

    % Implictily grab input
l_  % Push -1 to the stack
^   % Raise the input to the -1 power
    % Implicitly display the result

Rogex, 15 bytes

701300001600200

Try it online!

The actual language isn't on TIO yet, so a python 3.8 interpreter with the program in the code section and the python interpreter split in the header and footer is provided

Rogex is a newly developed language that I've recently discovered, so I though I'd give it a crack and write an answer.

Explained

701 300 # Set the buffer to 1 and place it in cell 0
001     # Get numeric input and place it into the buffer
600 200 # Divide cell 0 (1) by the buffer (input) and print

(╭☞´• ᗜ •`)╭☞ 100 answers! Woot! (⌐■◡■)

W, 3 bytes

You know, we can't beat the built-ins.

1S/

Explanation

a1S  % Stack : 1 a
   / % Divide.(1/a)
     % Output.

Keg, 1 byte

Try it online!

Keg, 3 bytes(SBCS)

1¿/

TIO Divide 1 by friendly input

SenseTalk, 16 bytes

params r
put 1/r

Explanation

params r # accept input
put 1/r  # get the reciprocal

AWK, 10 7 bytes

$0=1/$0

Usage:

awk '$0=1/$1' <<< "some number here"

or use the TIO link : Try it online!

Explanation: Replace the input line with its reciprocal. This is then evaluated and the entire line is printed if the evaluation in non-zero. Since the result can't be 0 we don't need to worry about not receiving output.

KoopaScript, 48 bytes

def a i inp;setath o 1 / \%vuserInput;print \%vo

And how it works (KS isn't really golfable yet but it's fun nonetheless):

def a i                                          - define a function and call it a lot
        inp;                                     - pause execution until input
            setath o 1 / \%vuserInput;           - set 'o' to 1 / the input
                                      print \%vo - output 'o'

Try it online (paste the code into the left-hand box, press enter, then type a number, press enter, etc)

Now that KS has input, I can finally start using it for stuff that involves interaction :D (Tell me if this should be non-competing :P)

Bash, 15 bytes

dc -e"Fk$1_1^p"

Try it online!

dc               ::Use dc calculation
   -e            ::Evaluate argument as dc code
     "         " ::Quote
      Fk         ::F sig-figs (F is hex for 15)
        $1       ::$1 is initial value (the first argument)
           _1^   ::Raise $1 to power of -1
              p  ::Print result

Julia, 3 bytes

3 bytes saved thanks to @gggg

inv

Try it online!

Returns the matrix inverse.

Attache, 4 bytes

1&`/

Try it online!

This is division (`/) left-bonded with 1, which is equivalent to reciprocal.

OIL, 1428 1420 bytes

Oh well. I thought I might as well try it, and I did in the end succeed. There's just one downside: It takes almost as long to run as it took to write.

The program is separated into multiple files, which have all 1-byte-filenames (and count for one additional byte in my byte calculation). Some of the files are part of the example files of the OIL language, but there's no real way to consistently call them (there's no search path or anything like that in OIL yet, so I don't consider them a standard library), but that also means that (at the time of posting) some of the files are more verbose than neccessary, but usually only by a few bytes.

The computations are accurate to 4 digits of precision, but calculating even a simple reciprocal (such as the input 3) takes a really long time (over 5 minutes) to complete. For testing purposes, I've also made a minor variant that's accurate to 2 digits, which takes only a few seconds to run, in order to prove that it does work.

I'm sorry for the huge answer, I wish I could use some kind of spoiler tag. I could also put the bulk of it on gist.github.com or something similar, if desired.

Here we go: main, 217 bytes (file name doesn't count for bytes):

5
1
1
4
-
14
a
5
Y
10
5
8
14
29
12
1
97
1
97
24
9
24
13
99

1
1
4
31
1
35

14
a
32
.
10
32
8
50
41
1
53
2
14
b
1
1
6
72
14
c
5
0000
14
d
6
6
10
74
5
63
68
1
6
1
6
72
14
b
1
5
1
77
0
14
e
1
0
14
f
1
1
1
31
0
14
b
0
0
4

a (checks if a given string is in a given other string), 74+1 = 75 bytes:

5
0
5
1
14
g
2
0
10
2
30
24
13
10
1
31
27
18
14
h
1
1
6
4
4
30
3
4
29
N
Y

b (joins two given strings), 20+1=21 bytes:

5
0
5
1
13
0
2
0
4
0

c (given a symbol, splits the given string at its first occurrence), 143+1=144 bytes (this one is obviously still golfable):

5
0
5
83
12
83
83





10
84
0
21
17
8
13
6
12
1
13
1
1
5
2
14
i
45
1
1
83
1
1
45
2
14
i
57
1
9
45
13
84

1



8
13
1
13
56
13
13

2
4
1
11
4
2

d (given a string, gets the first 4 characters), 22+1=23 bytes:

5
0
12
0
20
13
21
4

4

e (high-level division (but with zero division danger)), 138+1=139 bytes:

5
0
5
1
.
.
1
1
6
14
j
0
0
1
0
4
10
11
1
58
21
14
b
4
4
1
1
15
14
k
0
15
1
6
1
14
j
0
0
1
0
5
14
b
4
4
9
8
10
8
11
58
53
10
11
1
58
25
4
4

f (moves a dot 4 positions to the right; "divides" by 10000), 146+1=147 bytes:

5
.
12
0
100
10
101
1
14
10
8
6
6
5
1
6
34
1
6
33
8
33
1
6
37
8
37
10
55
3
48
32
1
102
101
1
1
102
9
55
8
34
8
33
8
37
6
27
1
100
53
13
101


4

4

g (checks if a string starts with a given character), 113+1=114 bytes:

5
0
5
1
12
0
100
12
1
200
1
6
2
1
9
3
8
2
8
3
9
100
9
200
1
2
31
1
3
32
10


39
35
4
38
3
N
10
100
5
44
16
4
46
Y

h (returns everything but the first character of a given string), 41+1=42 bytes:

5
0
12
0
100
9
100
1
100
12
13
102

0
4
0

i (subtracts two numbers), 34+1=35 bytes:

5
0
5
1
10
16
1
14
9
9
0
9
1
6
4
0

j (low-level division that doesn't work in all cases), 134+1=135 bytes:

5
0
5
2
10
2
19
52
9
1
2
3
10
23
2
28
17
10
23
0
35
22
9
0
9
2
6
12
8
1
1
3
2
6
17
10
23
2
46
40
9
2
9
3
6
35
4
1
11
4
3
3
4
19
11
4
0

k (multiplication), 158+1=159 bytes:

5
0
5
1
8
0
9
0
8
1
9
1
1
5
2
12
0
68
10
69
66
23
29
8
7
14
l
0
0
12
1
68
10
69
66
37
43
8
7
14
l
1
1
10
0
5
56
48
9
0
14
m
2
1
6
43
10
7
3
61
63
4
66
4
2
3
-

l (return absolute value), 58+1=59 bytes:

5
-
12
0
24
10
25
1
13
10
4
0
3
9
24
1
24
20
13
26

0
6
10

m (addition), 109+1=110 bytes:

5
0
5
1
8
0
9
0
8
1
9
1
12
1
46
10
47
45
31
20
10
1
43
42
25
9
1
8
0
6
20
10
1
43
42
36
8
1
9
0
6
31
4
0
3
-

Aceto 1.0, 4 3 bytes non-competing

Non-competing because the challenge predates Aceto. Assumes input number is on the stack, and leaves it on the stack.

1s:

1 pushes 1 on the stack, s swaps the top two values, and : does floating point division.

Also, this is the first Aceto answer!

edit: Saved 1 byte

ARBLE, 3 bytes

1/x

Try it online!

Common Lisp, 1 byte

/

Try it online!

Groovy, 9 bytes

{1.0g/it}

Needs the .0g to denote big decimal notation on the 1, making the it unbox itself as a BigDecimal.

Input of 7.29349129124513204632593467635245678734521456789

Results in 0.13710854789123656486815482305643737234188188122

If you use an input of 214700000000000, however, without the .0g...

You get an error or nothing.

APL, 1 byte

÷

÷ Computes reciprocal when used as monadic function. Try it online!

Uses the Dyalog Classic character set.

Cheddar, 5 bytes

1&(/)

Try it online!

This uses &, which bonds an argument to a function . In this case, 1 is bound to the left hand side of /, which gives us 1/x, for an argument x. This is shorter than the canonical x->1/x by 1 byte.


Alternatively, in the newer versions:

(1:/)

8087 machine code, 4 bytes

d9 e8   |   fld1
d8 f1   |   fdiv st0, st1

The obvious/trivial solution. Expects input in register st0.

Perl 5, 7 bytes

The obvious subroutine.

{1/pop}

Batch, 69 67 + 39 (vbs section) = 106 bytes

a.bat

@for /f "skip=1" %%n in ('cscript //nologo b.vbs 1/%1')do @echo %%n

Explanation:

b.vbs

WScript.Echo Eval(WScript.Arguments(0))

Explanation:(my guess, I'm not good at VBS)


Test cases

called from command line:

>a.bat 0.5134
1.94779898714453

>a.bat -0.5
-2

Batch can't handle floating point division....

Jelly , 11 Bytes

²Nṭ1,0ÆrḢ×Ṡ

This works without the built-in inverse function . (Who uses that anyway?).

Try it online!

How it works

²Nṭ1,0ÆrḢ×Ṡ
   1,0      # Look at the list [1,0]
  ṭ         # Append (to the end)
²N          #  the negative of the square of the input
      Ær    # Find the roots to the polynomial with coefficients corresponding to the list as [greater root,lower root] pair
        Ḣ   # Head; get the first element of the roots (always positive)
         ×Ṡ # Multiply by the sign of the input (to accommodate negative input)

Convex, 1 byte

¹

Try it online!

Fourier (Non-Competing), 79 bytes

1~RI~X<0{1}{0-1~R45a}X*R~XL*2+2/2~UX{1}{0~U}10P10/X~DL+U~p10Pp~TD/To*T~A46aD-Ao

Try it online!

This is non-competing for two reasons:

So, this answer poses a challenge: can you complete this challenge in Fourier in the range -9999 <= x <= 9999? There are two bounties up for grabs:

Note that on the Fourier github repo (https://github.com/beta-decay/Fourier/tree/master/fourIDE/editor) the FourIDE is up to date with L and P.

To-do list

PHP, 24 bytes

echo(1/(float)$argv[1]);

This is my first answer, tell me if I can somehow shorten it! Try it online!

When trying it online, just change the argument to the desired number n of which you want to get 1/n

Very straightforward approach.

Axiom, 57 bytes

f(x)==(y:=abs(x);y>9999 or y<0.0001=>"ObjFloatErr ";1./x)

test code and results

(21) -> [[i,f(i)] for i in [-2,-1,-0.0001,-0.00001,9999,10000]]
   (21)
   [[- 2.0,- 0.5], [- 1.0,- 1.0], [- 0.0001,- 10000.0],
    [- 0.00001,"ObjError 1/x"], [9999.0,0.0001000100 0100010001],
    [10000.0,"ObjError 1/x"]]

Haskell, 4 bytes

(/)1

Currying FTW!

CGL (CGL Golfing Language), 6 bytes (non-competing)

This language postdates this challenge.

-÷Ⓧ

Explanation:

- decrements the current stack, so it is now -1, where input is placed

÷ Divides the first element of the stack by the second if it exists, otherwise (this case) it divides 1 by the first (reciprocal)

Output the last stack item (the result of ÷) and exit

Brain-Flak, 772 536 530 482 480 + 1 = 481 bytes

Since Brain-Flak does not support floating point numbers I had to use the -c flag in order input and output with strings, hence the +1.

(({})[((((()()()()())){}{})){}{}]){((<{}>))}{}({}<{({}[((((()()()){}())()){}{}){}]<>)<>}<>{({}<>[()()])<>}{}([]<{({}<>[()()])<>}>)<>([[]](())){({}()<((((((({}<(((({})({})){}{}){}{})>)({})){}{}){})({})){}{}){})>)}{}({}(<>))<>([()]{()<(({})){({}[()])<>}{}>}{}<><{}{}>){({}<((()()()()()){})>(<>))<>([()]{()<(({})){({}[()])<>}{}>}{}<><([{}()]{})>)}{}<>({}()<<>([]){{}({}<>)<>([])}{}<>>){({}[()]<({}<>((((()()()){}){}){}){})<>>)}{}([()()])([]){{}({}<>((((()()()){}){}){}){})<>([])}<>>)

Try it online!

Explanation

The first thing we need to take care of is the negative case. Since the reciprocal of a negative number is always negative we can simply hold on to the negative sign until the end. We start by making a copy of the top of the stack and subtracting 45 (the ASCII value of -) from it. If this is one we put a zero on the top of the stack, if not we do nothing. Then the we pick up the top of the stack to be put down at the end of the program. If the input started with a - this is still a - however if it is not we end up picking up that zero we placed.

(({})[((((()()()()())){}{})){}{}]){((<{}>))}{}
({}<

Now that that is out of the way we need to convert the ASCII realizations of each digit into there actual values (0-9). We also are going to remove the decimal point . to make computations easier. Since we need to know where the decimal point started when we reinsert it later we store a number to keep track of how many digits were in front of the . on the offstack.

Here is how the code does that:

We start by subtracting 46 (the ASCII value of .) from each element on the stack (simultaneously moving them all onto the offstack). This will make each digit two more than should be but will make the . exactly zero.

{({}[((((()()()){}())()){}{}){}]<>)<>}<>

Now we move everything onto the left stack until we hit a zero (subtracting two from each digit while we go):

{({}<>[()()])<>}{}

We record the stack height

([]<

Move everything else onto the left stack (once again subtracting the last two from every digit as we move them)

  {({}<>[()()])<>}

And put the stack height we recorded down

>)

Now we want to combine the digits into a single base 10 number. We also want to make a power of 10 with twice the digits as that number for use in the calculation.

We start by setting up a 1 on top of the stack to make the power of 10 and pushing the stack height minus one to the on stack for the use of looping.

<>([][(())])

Now we loop the stack height minus 1 times,

{
 ({}[()]<

Each time we multiply the top element by 100 and underneath it multiply the next element by 10 and add that to the number below.

 ((((((({}<(((({})({})){}{}){}{})>)({})){}{}){})({})){}{}){})

We end our loop

 >)
}{}

Now we are finally done with the set up and can begin the actual calculation.

({}(<>))<>([()]{()<(({})){({}[()])<>}{}>}{}<><{}{}>)

That was it...

We divide the power of 10 by the modified version of the input using 0 ''s integer division algorithm as found on the wiki. This simulates the division of 1 by the input the only way Brain-Flak knows how.

Lastly we have to format our output into the appropriate ASCII.

Now that we have found ne we need to take out the e. The first step to this is converting it to a list of digits. This code is a modified version of 0 ''s divmod algorithm.

{({}<((()()()()()){})>(<>))<>([()]{()<(({})){({}[()])<>}{}>}{}<><([{}()]{})>)}{}

Now we take the number and add the decimal point back where it belongs. Just thinking about this part of the code brings back headaches so for now I will leave it as an exercise for the reader to figure out how and why it works.

<>({}()<<>([]){{}({}<>)<>([])}{}<>>){({}[()]<({}<>((((()()()){}){}){}){})<>>)}{}([()()])([]){{}({}<>((((()()()){}){}){}){})<>([])}<>

Put the negative sign down or a null character if there is no negative sign.

>)

sed, 575 + 1 (-r flag) = 723 718 594 588 576 bytes

s/$/\n0000000000/
tb
:b
s/^0+//
s/\.(.)(.*\n)/\1.\2/
tD
bF
:D
s/.*/&&&&&&&&&&/2m
tb
:F
s/\.//
h
s/\n.+//
s/-//
:
s/\b9/;8/
s/\b8/;7/
s/\b7/;6/
s/\b6/;5/
s/\b5/;4/
s/\b4/;3/
s/\b3/;2/
s/\b2/;1/
s/\b1/;0/
s/\b0//
/[^;]/s/;/&&&&&&&&&&/g
t
y/;/0/
x
G
s/[^-]+(\n0+)\n(0+)/\2\1/
s/\n0+/&&\n./
:a
s/^(-?)(0*)0\n0\2(.*)$/\10\2\n\30/
ta
s/.*/&&&&&&&&&&/2m
s/\n0(0*\n\..*)$/\n\1 x/
Td
s/x//
ta
:d
s/[^-]+\n//
s/-(.+)/\1-/
s/\n//
:x
s/^0{10}/0x/
s/(.)0{10}/0\1/
tx
s/00/2/g
s/22/4/g
y/0/1/
s/41/5/g
s/21/3/g
s/45/9/g
s/44/8/g
s/43/7/g
s/42/6/g
y/ /0/
s/([1-9])0/\1/g
y/x/0/
s/(.+)-/-\1/

Try it online!

Note: floats for which the absolute value is less than 1 will have to be written without a leading 0 like .5 instead of 0.5. Also the number of decimal places is equal to enter image description here, where n is the number of decimal places in the number (so giving 13.0 as input will give more decimal places than giving 13 as input)

This is my first sed submission on PPCG. Ideas for the decimal-to-unary conversion were taken from this amazing answer. Thanks to @seshoumara for guiding me through sed!

This code performs repeated long division to get the result. The division only takes ~150 bytes. The unary-decimal conversions take the most bytes, and a few other bytes go to supporting negative numbers and floating-point inputs

Explanation

Explanation on TIO

#Append 10 0's. This is the dividend, I think
s/$/\n0000000000/
tb

#This branch moves the decimal point 1 to the right
:b
#Remove leading 0's (such as from numbers like .05 => 0.5)
s/^0+//
#Move the decimal point 1 to the right
s/\.(.)(.*\n)/\1.\2/
#If the above has resulted in a successful substitution, go to branch D
tD
#else go to branch F
bF

#Multiply the dividend by 10; also keeps the mood positive
:D
s/.*/&&&&&&&&&&/2m
#Then go back to branch b
tb

:F
#Remove decimal point since it is all the way to the right now
s/\.//
h
#Remove "unnecessary" things
s/\n.+//
s/-//

#Convert to unary
:
s/\b9/;8/
s/\b8/;7/
s/\b7/;6/
s/\b6/;5/
s/\b5/;4/
s/\b4/;3/
s/\b3/;2/
s/\b2/;1/
s/\b1/;0/
s/\b0//
/[^;]/s/;/&&&&&&&&&&/g
t
y/;/0/

#Append the unary number to the pattern space
x
G
s/[^-]+(\n0+)\n(0+)/\2\1/

### END Decimal-to-Unary conversion
### BEGIN Division

#Performs Long Division
#Format looks something like this (can't remember): divisor\ndividend\ncount\nresult
#Count controls how many decimal places the answer should have; dp => 10^numDigits(n)
#Removes divisor from dividend and then add a 0 to result
#Once the dividend becomes too small, append a space to result and remove a zero from count
#Rinse and repeat
s/\n0+/&&\n./
:a
s/^(-?)(0*)0\n0\2(.*)$/\10\2\n\30/
ta
s/.*/&&&&&&&&&&/2m
s/\n0(0*\n\..*)$/\n\1 x/
Td
s/x//
ta

### END DIVISION
### BEGIN Unary-to-Decimal conversion

:d
s/[^-]+\n//
s/-(.+)/\1-/
s/\n//

#"carry over"-ing; .0000000000 => 0.
:x
s/^0{10}/0x/
s/(.)0{10}/0\1/
tx

#Convert each pair of unary 0s to their decimal counterparts
s/00/2/g
s/22/4/g
y/0/1/
s/41/5/g
s/21/3/g
s/45/9/g
s/44/8/g
s/43/7/g
s/42/6/g
y/ /0/
s/([1-9])0/\1/g
y/x/0/
s/(.+)-/-\1/

Edits

Python 2.7, 17 25 bytes

Full program:

print'%.4f'%(1.0/input())

Pyth, 3 2 bytes

-1 byte thanks to Steven Hewitt

c1

c is float division, with 1 and implicit input.

GNU sed, 377 362 + 1(r flag) = 363 bytes

Warning: the program will eat all the system memory trying to run and require more time to finish than you'd be willing to wait! See below for an explanation and a fast, but less precise, version.

s:\.|$:,,,,,,,,:;:i;s:,(,+)(\w):\2\1:;ti
h;:;s:\w::2g;y:9876543210:87654321\t :;/ /!s:,:@,:;/\s/!t;x;s:-?.::;x;G;s:,.*::m;s:\s::g;/\w/{s:@+:&&&&&&&&&&:;t}
/@,-?@/!{s:^:10000000,:;h;t}
:l;s:(@+)(,-?\1):\2;:;tl;s:,::;s:@+;?@+::
s:-?:&0:;:c;s:\b9+:0&:;s:.9*;:/&:;h;s:.*/::;y:0123456789:1234567890:;x;s:/.*::;G;s:\n::;s:;::;/;/tc
:f;s:(\w)(,+),:\2\1:;tf;s:,:.:;y:,:0:

This is based on the Retina answer by Martin Ender. I count \t from line 2 as a literal tab (1 byte).

My main contribution is to the conversion method from decimal to plain unary (line 2), and vice versa (line 5). I managed to significantly reduce the size of code needed to do this (by ~40 bytes combined), compared to the methods shown in a previous tip. I created a separate tip answer with the details, where I provide ready to use snippets. Because 0 is not allowed as input, a few more bytes were saved.

Explanation: to better understand the division algorithm, read the Retina answer first

The program is theoretically correct, the reason why it consumes so much computational resources is that the division step is run hundred of thousands of times, more or less depending on the input, and the regex used gives rise to a backtracking nightmare. The fast version reduces the precision (hence the number of division steps), and changes the regex to reduce the backtracking.

Unfortunately, sed doesn't have a method to directly count how many times a backreference fits into a pattern, like in Retina.

s:\.|$:,,,,,,,,:             # replace decimal point or end of string with 8 commas
:i                           # loop to generate integer (useful for unary division)
  s:,(,+)(\w):\2\1:          # move 1 digit in front of commas, and delete 1 comma
ti                           # repeat (':i')
h;:                          # backup pattern and start decimal to unary conversion
  s:\w::2g                   # delete decimal digits, except the first (GNU magic)
  y:9876543210:87654321\t :; # transliterate characters
  / /!s:,:@,:                # if no space is present, append a unary digit ('@')
  /\s/!t                     # if no whitespace is present, go back to ':'
  x;s:-?.::;x                # delete first digit and the negative sign from backup
  G;s:,.*::m;s:\s::g         # append backup, delete whitespace and duplicate stuff
/\w/{s:@+:&&&&&&&&&&:        # if decimal digit left, multiply unary number by 10
t}                           # and repeat (':')
/@,-?@/!{                    # if only one unary number found (the input)
  s:^:10000000,:             # prepend decimal 10^7 separated by a comma
h;t}                         # backup pattern and convert new number to unary also
:l                           # start unary division loop (tons of RAM and time!!!)
  s:(@+)(,-?\1):\2;:         # delete as many '@'s from 10^7, as found in unary
                             #input, and add one ';' (new unary digit)
tl                           # repeat (':l')
s:,::;s:@+;?@+::             # delete leftover stuff
s:-?:&0:;:c                  # prepend zero and start unary to decimal conversion
  s:\b9+:0&:                 # if only 9s found, prepend zero to them
  s:.9*;:/&:                 # separate the digit(s) that would change on increment
  h;s:.*/::                  # backup, delete all (non-changing) digits (till '/')
  y:0123456789:1234567890:   # increment changing digit(s)
  x;s:/.*::                  # delete changing digits from backup
  G;s:\n::                   # append backup, delete newline
  s:;::                      # delete one unary digit (';')
/;/tc                        # if unary portion left, repeat (':c')
:f                           # loop to generate floating-point number
  s:(\w)(,+),:\2\1:          # move 1 digit after the commas, and delete 1 comma
tf                           # repeat (':f')
s:,:.:                       # turn first comma into a decimal point
y:,:0:                       # turn the rest of commas into zeroes (final result)
                             # implicit printing

For a fast and safe version of the program, but less precise, you can try this online.

JavaScript(ES7), 8 bytes

x=>x**-1

f=x=>x**-1;
console.log(f(0.5134));

REXX, 12 bytes

say 1/arg(1)

Divides 1 by first argument. Precision is decided by NUMERIC DIGITS but defaults to at least 9 decimals.

Javascript ES6, 6 bytes

x=>1/x

Try it online!

Javascript defaults to floating point division.

C, 15 12 bytes

#define f 1/

Try it online!

16 13 bytes, if it needs to handle integer input also:

#define f 1./

So you can call it with f(3) instead of f(3.0).

Try it online!

Thanks to @hvd for golfing 3 bytes!

Racket 7 bytes

(/ 1 x)

Full function:

(define (f x)
  (/ 1 x))

Testing:

(f 1.56)

Output:

0.641025641025641

Bash + bc, 12 bytes

bc -l<<<1/$1

bc defaults to integer division, which would be a problem, but running bc with the -l flag loads a math library that allows for floating point division. The $1 takes the first command line argument passed to the Bash script and the <<< passes the string with the expanded argument to bc.

Emacs Lisp, 11 bytes

(/ 1(read))

Elisp defaults to integer division, so the input will have to be given as floating point, e.g. 1.0 instead of 1. The engine evaluates the (read) statement to get the input and then evaluates the (/ ...) statement, and outputs the answer to stdout.

TI-Basic (TI-84 Plus CE), 6 5 2 bytes

Ans⁻¹

-1 byte thanks to Timtech.

-3 bytes with Ans thanks to Григорий Перельман.

Ans and ⁻¹ are one-byte tokens.

TI-Basic implicitly returns the last value evaluated (Ans⁻¹).

Retina, 99 91 bytes

1`\.|$
8$*;
+`;(;*)(\d)
$2$1
\d+
$*1,10000000$*
(1+),(\1)+1*
$#2
+`(\d)(;+);
$2$1
1`;
.
;
0

Try it online!

Woohoo, sub-100! This is surprisingly efficient, considering that it creates (and then matches against) a string with more than 107 characters at one point. I'm sure it's not optimal yet, but I'm quite happy with the score at the moment.

Results with absolute value less than 1 will be printed without the leading zero, e.g. .123 or -.456.

Explanation

The basic idea is to using integer division (because that's fairly easy with regex and unary arithmetic). To ensure that we get a sufficient number of significant digits, we divide the input into 107. That way, any input up to 9999 still results in a 4-digit number. Effectively, that means we're multiplying the result by 107 so we need to keep track of that when later reinsert the decimal point.

1`\.|$
8$*;

We start by replacing the decimal point, or the end of the string if there is no decimal point with 8 semicolons. The first one of them is essentially the decimal point itself (but I'm using semicolons because they don't need to be escaped), the other 7 indicate that value has been multiplied by 107 (this isn't the case yet, but we know we will do that later).

+`;(;*)(\d)
$2$1

We first turn the input into an integer. As long as there are still digits after the decimal point, we move one digit to the front and remove one of the semicolons. This is because moving the decimal point right multiplies the input by 10, and therefore divides the result by 10. Due to the input restrictions, we know this will happen at most four times, so there are always enough semicolons to be removed.

\d+
$*1,10000000$*

Now that the input is an integer, we convert it to unary and append 107 1s (separated by a ,).

(1+),(\1)+1*
$#2

We divide the integer into 107 by counting how many backreferences to it fit ($#2). This is standard unary integer division a,b --> b/a. Now we just need to correct the position of the decimal point.

+`(\d)(;+);
$2$1

This is basically the inverse of the second stage. If we still have more than one semicolon, that means we still need to divide the result by 10. We do this by moving the semicolons one position to the left and dropping one semicolon until we either reach the left end of the number, or we're left with only one semicolon (which is the decimal point itself).

1`;
.

Now is a good time to turn the first (and possibly only) ; back into ..

;
0

If there are still semicolons left, we've reached the left end of the number, so dividing by 10 again will insert zeros behind the decimal point. This is easily done by replacing each remaining ; with a 0, since they're immediately after the decimal point anyway.

LOLCODE, 63, 56 bytes

HOW DUZ I r YR n 
VISIBLE QUOSHUNT OF 1 AN n
IF U SAY SO

7 bytes saved thanks to @devRicher!

This defines a function 'r', which can be called with:

r 5.0

or any other NUMBAR.

Try it online!

Elixir, 7 bytes

&(1/&1)

Anonymous function defined using the capture operator.

Full program:

f=
&(1/&1)

IO.inspect(f.(0.5134))  # 1.94779898714453

Try it online!

C#, 7 6 bytes

Saved a byte thanks to David Conrad.

x=>1/x;

Anonymous function which returns the inverse of a number.

Full program with test cases:

using System;

public class Program
{
    public static void Main()
    {
        Func<double, double> f =
        x=>1/x;
        
        // test cases:
        Console.WriteLine(f(0.5134));
        Console.WriteLine(f(0.5));
        Console.WriteLine(f(2));
        Console.WriteLine(f(2.0));
        Console.WriteLine(f(0.2));
        Console.WriteLine(f(51.2));
        Console.WriteLine(f(113.7));
        Console.WriteLine(f(1.337));
        Console.WriteLine(f(-2.533));
        Console.WriteLine(f(-244.1));
        Console.WriteLine(f(-0.1));
        Console.WriteLine(f(-5));
    }
}

bc + sh, 14 10 bytes

1/read()<NEWLINE>

Run bc with -l which sets the default scale to 20. That way both input and output have 20 digits after the decimal point.

Edit: Thanks DigitalTrauma for a tip on changing the answer from bc + sh to pure bc. Saved 4 bytes.

Scala, 15 Bytes

(x:Double)=>1/x

Don't think there's a shorter way to do this in Scala.

OCaml, 12

fun x->1./.x

The division of floats is done with the operator /..

Noodel, 1 byte

A command that takes the first character of a string and places at the end, for numbers takes the reciprocal of the number. The interpreter for Noodel is written in JavaScript which has double precision floating point numbers.

Try it:)


How it works

  # Implicitly pushes the number onto the stack.
ẹ # Takes the reciprocal of the input.
  # Implicitly prints the top of the stack to the screen.

C++ lambda function, 24 bytes

[](float x){return 1/x;} 

Full program

#include <iostream>

void main()
{
    auto y = [](float x){return 1/x;} ;
    std::cout << y(5) << std::endl;
}

TI-Basic, 2 bytes

Ansֿֿ ¹

You could also do 1/Ans (3) or Ans^~1 (4).

Vim, 10 8 bytes/keystrokes

C<C-r>=1/<C-r>"

Since V is backwards compatible, you may Try it online!

Java 7, 29 bytes

Golfed:

float i(float x){return 1/x;}

Ungolfed:

float i(float x)
{
    return 1 / x;
}

Pretty straight forward.

R, 8 bytes

1/scan()

Pretty straightforward. Directly outputs the inverse of the input.

Another, but 1 byte longer solution can be : scan()^-1, or even scan()**-1 for an additional byte. Both ^ and ** the power symbol.

dc, 7 6 bytes

Edit: saved 1 byte thanks to Digital Trauma

7k1?/p

Try it online!

Because dc treats the input as commands, negative numbers are recognized using _ as the negative sign, instead of -, which is interpreted as the subtraction command. This is allowed by this meta consensus.

Explanation:

7k           # set precision to 7 digits. This is needed to output at least 4
             #significant figures when the input is '6431' for example)
1?           # push 1, then push input number
/p           # divide and print result

Excel VBA, 7 Bytes

Anonymous VBE immediates window function that takes input from cell [A1] of type variantand expecting a (floating-point) number and outputs its inverse to the VBE immediates window. Does not handle improperly formatted input.

?1/[A1]

Taxi, 467 bytes

Go to Starchild Numerology:w 1 l 2 r 1 l 1 l 2 l.1 is waiting at Starchild Numerology.Pickup a passenger going to Divide and Conquer.Go to Post Office:w 1 r 2 r 1 r 1 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s 1 l 1 r.Pickup a passenger going to Divide and Conquer.Go to Divide and Conquer:e 4 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:e 1 r.Pickup a passenger going to Post Office.Go to Post Office:e 1 l 1 r.

Try it online!

Ungolfed:

Go to Starchild Numerology:west 1 left, 2 right, 1 left, 1 left, 2 left.
1 is waiting at Starchild Numerology.
Pickup a passenger going to Divide and Conquer.
Go to Post Office:west 1 right, 2 right, 1 right, 1 left.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery:south 1 left, 1 right.
Pickup a passenger going to Divide and Conquer.
Go to Divide and Conquer:east 4 left.
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery:east 1 right.
Pickup a passenger going to Post Office.
Go to Post Office:east 1 left, 1 right.

Brachylog, 2 bytes

/₁

Try it online!

For the sake of completeness…

Explanation

/, by default, takes a list of 2 numbers [A, B] as input and unify its output with A divided by B.

When / has a subscript, it takes a single number as input unify its output with that number divided by the subscript. For example, /₄₂ will divide the input number by 42.

The only exception is if the subscript is 1 (because dividing by 1 is kind of useless). In that case, it unifies its output with the inverse of its input.

PHP, 11

<?=1/$argn;

Run with echo <n> | php -nR '<code

Dyvil, 5 Bytes

1 / _

Unfortunately we need the extra white space because /_ would be a single operator, and 1/ _ would parse differently

Usage:

let f: double -> double = 1 / _
print(f(2)) // 0.5

Racket, 11 bytes

(/ 1(read))

Try it online!

Perl 6, 3 bytes

1/*

Try it

This also works, but is 5 or 6 bytes
You can use (superscript minus) at 3 bytes, or ¯ (macron) which is 2 bytes

*⁻¹

Try it

Scala, 3 bytes

1/_

This defines a lambda equivalent to x => 1/x (_ is a placeholder for the argument). Use by assigning it to a variable, then calling it, like this:

val f: Double => Double = 1/_
f(5) // 0.2

Actually, 1 byte

ì

From the docs:

8D (ì): pop a: push 1/a

Try It Online

In Seriously, it would be two bytes:

x86_64 Linux machine language, 5 bytes

0:       f3 0f 53 c0             rcpss  %xmm0,%xmm0
4:       c3                      retq

To test this, you can compile and run the following C program

#include<stdio.h>
#include<math.h>
const char f[]="\xf3\xf\x53\xc0\xc3";
int main(){
  for( float i = .1; i < 2; i+= .1 ) {
    printf( "%f %f\n", i, ((float(*)(float))f)(i) );
  }
}

Try it online!

Haskell, 4 bytes

(1/)

Try it online!

J, 1 byte

%

% is a function giving the reciprocal of its input. You can run it like this

   % 2
0.5

Forth, 3 bytes

1/f

Try it online

Takes a floating point literal, which in Forth must be in scientific notation, like 5e-4 for 0.0005 or 2e3 for 2000.0. The result will be left on the floating point stack.

Reference on number conversion in Forth.

ZX Spectrum BASIC, 13 bytes

1 INPUT A: PRINT SGN PI/A

Notes:

ZX81 version for 17 bytes:

1 INPUT A
2 PRINT SGN PI/A

JSFuck, 3320 bytes

JSFuck is an esoteric and educational programming style based on the atomic parts of JavaScript. It uses only six different characters ()[]+! to write and execute code.

[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]((!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+!+[]]+(+(+!+[]+(!+[]+[])[!+[]+!+[]+!+[]]+[+!+[]]+[+[]]+[+[]])+[])[!+[]+!+[]]+[+!+[]]+(![]+[+![]])[([![]]+[][[]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]]()[+!+[]+[+[]]]+(!![]+[])[+[]]+(+(+!+[]+[+[]]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(+![]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(+![]+[![]]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]](!+[]+!+[]+[+!+[]])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]+!+[]])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]

Try it online!

alert(
  /* empty array       */ []
  /* ['fill']          */ [(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]
  /* ['constructor']   */ [([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]]
  /* ('return+1/this') */ ((!![]+[])[+!+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+([][[]]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+!+[]]+(+(+!+[]+(!+[]+[])[!+[]+!+[]+!+[]]+[+!+[]]+[+[]]+[+[]])+[])[!+[]+!+[]]+[+!+[]]+(![]+[+![]])[([![]]+[][[]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[!+[]+!+[]+!+[]]]()[+!+[]+[+[]]]+(!![]+[])[+[]]+(+(+!+[]+[+[]]+[+!+[]]))[(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(+![]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(+![]+[![]]+([]+[])[([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]])[!+[]+!+[]+[+[]]]](!+[]+!+[]+[+!+[]])[+!+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]+!+[]])
  /* ['call']          */ [([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(![]+[])[+!+[]]+(![]+[])[!+[]+!+[]]+(![]+[])[!+[]+!+[]]]
  (prompt())
)

yup, 5 bytes

|0~-e

Try it online! This takes input from the top of the stack and leaves output on the top of the stack. The TIO link takes input from command line arguments, which is only capable of taking integer input.

Explanation

yup only has a few operators. The ones used in this answer are ln(x) (represented by |), 0() (constant, nilary function returning 0), (subtraction), and exp(x) (represented by e). ~ switches the top two members on the stack.

|0~-e     top of the stack: n    stack: [n]
|         pop n, push ln(n)      stack: [ln(n)]
 0        push 0                 stack: [ln(n), 0]
  ~       swap                   stack: [0, ln(n)]
   -      subtract               stack: [-ln(n)]
    e     exp                    stack: [exp(-ln(n))]

This uses the identity

x/y = e^(ln(x)-ln(y))

which implies that

QBIC, 5 bytes

:?1/a

Explanation:

:    get input from the cmd line, named 'a'
?    PRINT
1/a  1/a

Gol><>, 4 bytes

1I,h

Online interpreter link

C, 30 bytes

float f(float x){return 1./x;}

Bean, 7 6 bytes

Equivalent JavaScript:

(1/A)

Bean xxd-style hexdump:

00000000: 4ca5 3a8e 2043                           L¥:. C

Explanation

A is auto-initialized with the 1st input line JSON-parsed. (e.g. 5 is interpreted as JSON and becomes a number), and the program implicitly outputs 1/A.

Edit The "hack" I just realized is that removing the first byte of the AST binary doesn't seem to affect the compilation of the program...

Try the demo here.

Japt, 2 bytes

The obvious solution would be

1/U

which is, quite literally, 1 / input. However, we can do one better:

pJ

This is equivalent to input ** J, and J is set to -1 by default.

Try it online!

Fun fact: as p is the power function, so q is the root function (p2 = **2, q2 = **(1/2)); this means that qJ will work as well, since -1 == 1/-1, and therefore x**(-1) == x**(1/-1).

Python 2, 10 bytes

1..__div__

Try it online!

Jelly, 1 byte

İ

Try it online!

Mathematica, 4 bytes

1/#&

Provides you with an exact rational if you give it an exact rational, and with a floating-point result if you give it a floating-point result.

Mathics, 4 bytes

1/#&

Try it online!

Fortran 95, 23 bytes

function f(x)
f=1/x
end

Jellyfish, 3 bytes

p%i

Try it online!

Unary % computes the reciprocal. i is input, p is output.

Python, 12 bytes

lambda x:1/x

One for 13 bytes:

(-1).__rpow__

One for 14 bytes:

1 .__truediv__

Quetzalcoatl, 3 bytes

cfI

c takes input, f converts to a float, and I takes the inverse.

MATLAB / Octave, 4 bytes

@inv

Creates a function handle (named ans) to the built-in inv function

Online Demo

Java 8, 6 bytes

x->1/x

Almost the same as the JavaScript answer.

CJam, 4 bytes

1rd/

Try it online!

1     e# Push 1
 rd   e# Push input as a double
   /  e# Divide

Alternate solution:

rdW#

rd    e# Push input as a double
  W   e# Push -1
   #  e# Exponentiation

05AB1E, 1 byte

z

Try it online!

z # pop a  push 1 / a

Ruby, 10 bytes

->x{1.0/x}

Very simple