g | x | w | all
Bytes Lang Time Link
nan230712T134525Zmousetai
031C gcc230712T181512ZNoodle9
092APLNARS250307T170310ZRosario
9185C no standard library250306T074057ZCaydendW
012Itr230822T135300Zbsoelch
130Python230715T090825ZPM 2Ring
1144Minecraft Data Pack via Lectern230715T073059ZCommand
122Hexagony230712T232434ZCursorCo
071><> Fish230712T154836Zmousetai
085Python230712T143755ZThe Empt
146Swift 5.6230713T133451ZBbrk24
084Python230712T231122Zloopy wa
012Dyalog APL no builtin230712T175113ZRubenVer
002BQN230712T210524ZRubenVer
016Excel230712T140649ZJos Wool
008Jelly230712T171735Zcaird co
012Charcoal230712T174332ZNeil
020Ruby230712T161853ZJordan
024Python 3230712T160906ZThe Thon
018JavaScript Node.js230712T154337Zl4m2
018R230712T151421ZDominic

Builtins

These answers are in alphabetical order based on programming language.
If your answer is identical to an existing one, please combine them.

05AB1E, 4 bytes

žr.n

Try it online!

APL (Dyalog Unicode), 1 byte

Try it online!

Brachylog, 2 bytes

*₁

Try it online!

C (gcc) / PARI/GP / Julia polyglot, 3 bytes

log

Try it online in C (gcc)!
Attempt this online in PARI/GP!
Try it online in Julia!

CJam, 4 bytes

{ml}

Try it online!

Desmos, 2 Bytes

ln

Try it online!

Excel, 7 bytes

=LN(A1)

Go, 17 bytes

import."math"
Log

Attempt This Online!

J, 2 bytes

^.

Attempt This Online!

J-uby, 9 bytes

:log&Math

Attempt This Online!

Java, 9 bytes

Math::log

Try it online!

JavaScript (Node.js), 8 bytes

Math.log

Try it online!

Jelly, 2 bytes

Æl

Try it online!

Julia 1.0, 3 bytes

log

Try it online!

MATL, 2 bytes

Yl

Try it online!

MATLAB / Octave, 4 bytes

@log

Try it online!

Pascal, ≥ 5 bytes

The built‑in function ln fulfills the task. Its only parameter needs to be positive. Extended Pascal, ISO standard 10206, allows complex numbers, too.

ln(n)         { where `n` is an acceptable numerical expression}

Pyth, 2 bytes

.l

Try it online!

Python 3, 20 bytes

import math
math.log

Try it online!

Racket

(log z)

Try it online!

Rust, 7 bytes

f64::ln

Attempt This Online!

Swift, 40 32 bytes

import Glibc
let l={log($0+0.0)}

macOS-only Linux-only (works on macOS if you change Glibc to Darwin).

Thunno 2, 2 bytes

ÆN

Try it online!

Vyxal, 2 Bytes

∆L

Try it online!

Wolfram Language (Mathematica), 3 bytes

Log

Try it online!

C (gcc), 44 31 bytes

#define f(x)(pow(x,1e-9)-1)*1e9

Try it online!

Saved 13 bytes thanks to ceilingcat!!! :D

Port of Jos Woolley's Excel answer

APL(NARS), 92 chars

r←a phi b;e
r←b⋄e←÷10v*⌊⎕FPC÷3.322
b←r⋄a←2÷⍨a+b⋄r←√a×b⋄→2×⍳e<∣r-b

ln←{((2÷⍨⍵+1)phi√⍵)÷⍨⍵-1}

//12+23+31+26= 92 Here I would rewrite the function phi that one can find in the book

ESERCIZI E COMPLEMENTI DI ANALISI MATEMATICA 
VOLUME PRIMO - AUTORE: ENRICO GIUSTI

in the end of "capitolo 3". The same function the Autor says is useful for calculate the function arccos() too.

The problem that I see, is the wrong build of float numeric in computer as the number is in memory the sum of decimal part and fractional part and the dimension in memory of decimal part influence the fractional part and so the precision...

I remember that there is one model in that make float point decimal part, not influence the fractional part as memory space... Is it that the fixed point model?

P is a function for print the number in number of digits that have to be ok if number and its calculus not use numbers with decimal digits > ⎕fpc÷4 in my opinion... (it is as ⎕fpc÷4 is for decimal part and ⎕fpc÷4 is for fractional part , if the memory of decimal part is too much the precision decrease). The numeber that end with the v is the big float.

  P←{⍵⍕⍨⌊⎕fpc÷8}
  ln 0.1
¯2.302585093
  P ln 0.1
¯2.3025850929940459
  P ln 2
0.6931471805599454
  P ln 99
4.5951198501345889
  ⎕fpc←256
  P ln 99
4.5951198501345889________________
  P ln 99v
4.59511985013458992685243405181018
  ⎕fpc←1024
  P ln 99v
4.59511985013458992685243405181018070911668796958291607868795637640556221035045464682228621763009896899065578402005373000699157761

C (no standard library), 91 85 bytes

Because what's the fun in using log or pow?

p;i;float x,t,y;u(){for(y=1;--p;)y=1+t*y/p;}l(){for(t=88,i=99;u(p=99),i--;t+=x/y-1);}

Input value into x, call l() and get output into t.

Newton's method for calculating the logarithm and Taylor series (factorised) for calculating e^x. Interestingly, the series used by other problems come out as a few more bytes for me. This was my shortest solution I could find.

-6 bytes thanks to ceilingcat. Integers instead of floats as loop iterators.

Itr, 12 bytes

$x'¿Fäeäx-\-

online interpreter

check all test-cases

Explanation

Uses Newtons method starting at 0 to approximate the result.

$x            ; store the input in x
  '¿F         ; repeat 191 times (enough for all test-cases)
     äeäx-\-  ; replace top stack value y starting at 0 with
              ; y-(e^y-x)/e^y (step in Newton method)
              ; implicitly print result

Itr, 17 bytes

$xx>3*i'¿Fäeäx-\-

Also works for negative (and complex) inputs

x>3*i sets the initial value to 3i if the real part of the input is negative

Python, 130 bytes

def f(x):
 x,m=(1/x,-1)if x<1 else(x,1)
 while x>1.03:x,m=x**.5,m<<1
 r=x**.5
 return m*90*(x-1)/(7*x+32*((x+1)*r+2*x)**.5+12*r+7)

This algorithm is derived from Carlson's version of Borchard's algorithm, which uses a modified arithmetic-geometric mean. Carlson's version adds Richardson acceleration. See Carlson, B. C. “An Algorithm for Computing Logarithms and Arctangents.” Mathematics of Computation, Apr 1972 https://doi.org/10.2307/2005182

My version is essentially two loops of Carlson's, with range reduction. It only uses elementary operations and square roots. Its absolute error is under 5e-14. Here are some error plots: error plot, 0.1 - 1 error plot 1 - 100

Try it in SageMathCell

Minecraft Data Pack via Lectern, 1144 bytes

@function a:a
summon bat ~ ~ ~ {Attributes:[{Name:generic.armor}]}
data merge storage  {a:[[9.,-0.9,-0.69,-0.45,-0.26,-0.14,-0.073,-0.038,-0.02,-0.011,-0.0056,-0.0029,-0.0015,-7.6e-4,-3.9e-4,-2.e-4,-1.1e-4,-5.6e-5,-2.9e-5,-1.5e-5,-7.6e-6,-3.9e-6,-2.e-6,-1.1e-6,-5.6e-7],[-1073741824,1073741824,546146222,278783439,140411372,70331752,35347866,18065629,9420929,5157943,2618732,1354293,700005,354538,181900,93273,51298,26115,13523,6995,3544,1819,933,513,261]],Operation:2,UUID:[I;0,0,0,1]}
execute as @e[type=bat] run function a:b
@function a:b
data modify entity @s Attributes[].Base set from storage  i
data modify storage  Amount set from storage  a[0][0]
data modify entity @s Attributes[].Modifiers append from storage :
execute store result score  a run attribute @s generic.armor get
execute if score  a matches 1..29 store result entity @s Attributes[].Modifiers[-1].UUID[] int 1 store result score v a run data get storage  a[1][0]
attribute @s generic.armor modifier remove 0-0-0-0-1
execute if score  a matches 1..29 run scoreboard players operation o a += v a
data remove storage  a[][0]
execute if data storage  a[][] run function a:b

The function is a:a.

Takes input in data storage : i, as a double.

Outputs via a scoreboard o a, scaled up by 466320149.

If we cannot assume a clean world with no bats, it's +8 to start with a kill @e command. If we mustn't kill the player it's another +10 for [type=bat]. If we cannot assume the objective a already exists it's +34 for scoreboard objectives add a dummy. If we can't assume the value o doesn't exist yet it's +29 for scoreboard players set o a 0.

Using a variant of binary search, we go over the values in a, multiply our value by 1+x using attributes, and if it's 1 or more we keep the multiplication and add the log of 1/(1+x) to our answer. Because the log decreases by less than half in each step we get the correct answer.

We start with a multiplication by 10 to deal with the case of \$0.1\leq x<1\$. We only perform the multiplication if the result is less than 30, to prevent the value going over 100. We need to use 30 because generic.armor is clamped to it.

Uses the fact that the storage name in Minecraft can be empty, as can the score holder. The scoreboard objective could've been as well, but then scoreboard players operation o a += v a wouldn't work because spaces are trimmed at the end of each line.

Hexagony, 161 122 bytes

?.{10''2\}{}u44.\4476'*0&}=..$/:"-+{=&={{/.|"=}{{&={*={&1d000000}{{}240504"-~{&137{:_1&':!@..~<>".){{{=$/_"'\>{={<>(<\&1=/

Try it online!

Layed out:

       ? . { 1 0 ' '
      2 \ } { } u 4 4
     . \ 4 4 7 6 ' * 0
    & } = . . $ / : " -
   + { = & = { { / . | "
  = } { { & = { * = { & 1
 d 0 0 0 0 0 0 } { { } 2 4
  0 5 0 4 " - ~ { & 1 3 7
   { : _ 1 & ' : ! @ . .
    ~ < > " . ) { { { =
     $ / _ " ' \ > { =
      { < > ( < \ & 1
       = / . . . . .

My first go at a Hexagony program. Could probably still be golfed some, but I'm happy to have gotten it to side length 7.

Since there are no floats in Hexagony, input and output are both fixed point \$\lfloor n\cdot10^7\rfloor\$.

The algorithm

(skip to the second paragraph if you don't care how I came up with it or why it works)

The algorithm used to approximate here is one I came up with myself. I'm sure something like it has been done before, but I'll go over how the constraints of Hexagony led me to this particular method. The first useful observation is that all logarithms are the same, at least up to a constant multiple. That is, \$\log_a(x)=\frac{\log_b(x)}{\log_b(a)}\$. This is nice because \$\log_{10}\$ is easier to work with when dealing with decimal representations. In fact, it's super easy. We can approxiamte the base ten logarithm just by taking the length of the decimal representation! Unfortunately, on the range \$[0.1, 100]\$ this give us 4 possible output values. Not quite good enough. We need a way to make our numbers longer, but longer in a very specific way. Firstly, as I mentioned earlier, we can't even enter \$0.1\$ into Hexagony, so we pad the lengths and get some necessary input precision by multiplying everything by \$10^7\$. Then, we use another simple logarithm observation: \$\log(x)=\frac{1}{n}\log(x^n)\$. Which is to say, up to another constant multiple (which was already necessary), we can take our input to any power before taking the logarithm. Great, so we just take the input to some super high power, take the length of the result and multiply it by something. But there's still a problem. While this idea technically works, it means that we'd be multiplying and measuring the length of numbers millions of digits long. I'd never be able to verify any test cases. We've successfully made our numbers longer, now we need to make them shorter. So we break the large exponent into steps, and at each step we truncate the input. By looking at how much we truncate each time we can give an approximation for how long we think it would have gotten if it didn't truncate. This approxiamtion becomes our logarithm. So, for the actual algorihtm:

We take the input and keep a running count of how many digits long we think it is. We enter a loop. For each iteration, we square the input and double this running count (since squaring roughly doubles length). We then truncate the input to the first 7 digits, and add the number of digits we took off to our running count. Iterating 24 times gives us more than enough precision. We then take our predicted length, add a constant, multiply by a constant and print it out.

The agony

So how is this implemented exactly? I'll refer to the memory graph as it is labeled below. as well as the colored paths.

colored paths for reference memory after computing ln(2)

Note that I only use one instruction pointer for this program, which is probably not optimal. We begin on the blue path. This initializes some variables, putting the input in A, 10 in H, 100000000 in I, and 24 on L leaving the memory pointer in L. Then on to the main loop in green. The main loop first uses G and F to square A, then similarly uses E and K to double D. Moving the memory pointer to B, we then use the yellow path to redirect into a sub loop on the orange tiles. This sub loop uses B an C to divide A by 10, compare against I and increment D. Once the input is less than I, We use the red path to traverse back to the main loop, putting the memory pointer back on L and decrementing. L serves as the main loop counter. Once L is 0, we break out of the main loop and on to the purple track. The purple track uses C and J to do the final subtraction and multiplication on the output in D. The final output ends up in J

Visualizations done with hexagony.net.

><> (Fish), 71 bytes

Trying to solve this in ><> was the original inspiration for this challenge. Posting this now instead of waiting the usual 24 hours to hopefully inspire more esolang submissions.

i0a:1+?v~2*n;
2*1+:?v\:2*1+1$,$:@
}:{$-1//*,+1}:{-1
/$+@$~/\$31.
\1-20.

Hover over any symbol to see what it does

Try it

Based on the power series \$\ln(z)=2\sum_{n=0}^\infty\,\frac{1}{2n+1}\left(\frac{z-1}{z+1}\right)^{2n+1}\$ from this answer om math.se. ><> lacks exponentiation so that too must be done with a loop.

enter image description here

The green loop is the big sum while the grey loop raises to the power of 2n+1

Python, 85 Bytes

f=lambda x:sum(1/y for y in range(9**7,round(x*9**7)+1))if x>1else-f(1/x)if x-1else 0

Uses numerical integration.

Try It Online! (I've used the Pypy implementation in the TIO website since it's apparently 4x faster)

Swift 5.6, no imports, 146 bytes

Swift has no log or pow builtins -- you have to import those from C! Here's a Swift answer that doesn't use any imports:

let i:(Float,Int)->_={x,y in(0..<y).reduce(1){n,_ in n*x}}
func l(x:Float)->Float{2*(0...126).reduce(0){$0+i((x-1)/(x+1),2*$1+1)/(.init($1)*2+1)}}

SwiftFiddle link with test cases. Uses this method from the linked Math.SE post. 126 is just the magic number needed to get the requisite precision for \$\ln\left(99\right)\$.

This works in later versions of Swift, but I'm pinning it to 5.6 in case exponentiation is added in the future. i is a handwritten exponentiation function where the exponent must be a positive integer (called Int instead of UInt to save bytes).

Python, 84 bytes

def f(x):
 g=i=999;s=1|-(x>1);x=x**s-1
 while i:g=i+x*(i*i/g-(i:=i-1))
 return x*s/g

Attempt This Online!

Thanks @xnor for -1.

How?

Evaluates a continued fraction https://en.wikipedia.org/wiki/Euler%27s_continued_fraction_formula

Dyalog APL (no builtin), 13 12 bytes

Dyalog does have the builtin , but this way it's more fun :)

(⊢-1-÷∘*)⍣=⍨

Basically just Newton's method:

$$ x_{n+1} = x_n - \frac{f(x_n)}{f'(x_n)} $$

where (L is the number we are taking the log of)

$$ f(x) = e^x - L \\ f'(x) = e^x \\ x_{n+1} = x_n - \frac{e^{x_n} - L}{e^{x_n}} = x_n - 1 - \frac L {e^{x_n}} $$

(⊢-1-÷∘*)⍣=⍨
           ⍨ ⍝ ‎⁡x_0 is L
         ⍣=   ⍝ ‎⁢repeat Newton's method until x_n and x_n+1 are "equal":
 ⊢-1-         ⍝ ‎⁣x_n - 1 -
     ÷∘*      ⍝ ‎⁤L / e^x_n

💎 Created with the help of Luminespire at https://vyxal.github.io/Luminespire

"Equal" here means

$$ \left|x_n-x_{n+1}\right|\leq10^{-14}\max\left(\left|x_n\right|, \left|x_{n+1}\right|\right) $$

test cases

x ln(x) builtin ln(x) steps until convergence
0.1 -2.3025850929940455E0 -2.3025850929940455 8
0.25 -1.3862943611198906E0 -1.3862943611198906 7
0.5 -6.9314718055994520E-1 -0.6931471805599453 7
0.75 -2.8768207245178090E-1 -0.2876820724517809 7
0.9 -1.0536051565782634E-1 -0.10536051565782628 7
1 1.1102230246251565E-16 0 8
1.3 2.6236426446749117E-1 0.26236426446749106 7
2 6.9314718055994530E-1 0.6931471805599453 7
2.718281828459045 9.9999999999999990E-1 1 8
3.141592653589793 1.1447298858494002E0 1.1447298858494002 8
4 1.3862943611198906E0 1.3862943611198906 9
5 1.6094379124341003E0 1.6094379124341003 9
7 1.9459101490553135E0 1.9459101490553132 11
10 2.3025850929940460E0 2.302585092994046 14
53 3.9702919135521220E0 3.970291913552122 55
54.59815003314423 4 4 57
99 4.5951198501345900E0 4.59511985013459 100

gotta say, ln(1) resulting in 1e-16 is kinda annoying but well within the spec

This is 1 byte less than an implementation of Jos Woolley's, 1e9ׯ1+*∘1e¯9, but probably still has some room to be golfed further.

BQN, 2 bytes

⋆⁼­⁡​‎‎⁡⁠⁢‏‏​⁡⁠⁡‌⁢​‎‎⁡⁠⁡‏‏​⁡⁠⁡‌­
 ⁼  # ‎⁡The inverse of
⋆   # ‎⁢the function e^x

💎 Created with the help of Luminespire at https://vyxal.github.io/Luminespire

yeah ok this might be cheating :) can mark as community wiki or delete and move to the builtin answer if enough people complain

Excel, 19 16 bytes

With many thanks to Dominic van Essen for the 3-byte save:

=1E9*(A1^1E-9-1)

Previous:

=9^9*(A1^(1/9^9)-1)

Input in cell A1. The choice of 1E9 (i.e. 1000000000) is sufficient for the given test cases and required accuracy.

Jelly, 8 bytes

*İ}’×ʋȷ9

Try it online!

Uses the formula \$\ln(z) \approx 10^9(z^{10^{-9}} - 1)\$, adapted slightly from Jos Woolley's answer

How it works

*İ}’×ʋȷ9 - Main link. Takes z on the left
      ȷ9 - 10^9
     ʋ   - Last 4 links as a dyad f(z, 10^9):
  }      -   To 10^9:
 İ       -     Take it's reciprocal
*        -   Raise z to the power 10^-9
   ’     -   Decrement
    ×    -   Multiple by 10^9

Jelly, 14 bytes

’÷‘*÷ṛɗȷŻḤ‘¤SḤ

Try it online!

Uses the series definition $$\ln(z) = 2\sum^\infty_{n = 0} \frac 1 {2n+1} \left(\frac {z-1} {z+1}\right)^{2n+1}$$

For this series, \$1000\$ is more than enough to provide the required accuracy, as pointed out by mousetail for -1 byte!

How it works

’÷‘*÷ṛɗȷŻḤ‘¤SḤ - Main link. Takes z on the left
’              - z-1
  ‘            - z+1
 ÷             - (z-1)/(z+1)
           ¤   - Last links as a nilad:
       ȷ       -   10^4
        Ż      -   [0, 1, 2, ..., 1000]
         Ḥ     -   [0, 2, 4, ..., 2000]
          ‘    -   [1, 3, 5, ..., 2001]
      ɗ         - Last 3 links as a dyad f((z-1)/(z+1), [1, 3, 5, ..., 2001]):
   *            -   [(z-1)/(z+1), (z-1)/(z+1)^3, (z-1)/(z+1)^5, ...]
    ÷ṛ          -   [(z-1)/(z+1), ((z-1)/(z+1)^3)/3, ((z-1)/(z+1)^5)/5, ...]
             S  - Sum
              Ḥ - Unhalve; Double

Charcoal, 12 bytes

I×Xχχ⊖XNXχ±χ

Try it online! Link is to verbose version of code. Explanation: Port of @JosWooley's Excel answer.

       N        Input number
      X         Raised to power
         χ      Predefined variable `10`
        X       Raised to power
           χ    Predefined variable `10`
          ±     Negated
     ⊖          Decremented
 ×              Multiplied by
   χ            Predefined variable `10`
  X             Raised to power
    χ           Predefined variable `10`
I               Cast to string
                Implicitly print

Importing math.log from Python costs 11 bytes:

I▷math.logN

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

Ruby, 20 bytes

CW because it's literally a copy-and-paste of The Thonnu's Python 3 answer.

->n{1e9*(n**1e-9-1)}

Attempt This Online!

Python 3, 24 bytes

lambda x:1e9*(x**1e-9-1)

Try it online!

Port of Jos Woolley's Excel answer (and Dominic van Essen's R answer).

Somehow only 4 bytes off the built-in.

JavaScript (Node.js), 18 bytes

x=>1e9*(x**1e-9-1)

Try it online!

Port of Excel answer

R, 18 bytes

\(x)1e9*(x^1e-9-1)

Attempt This Online!

Port of Jos Woolley's Excel answer, using a constant of 1e9 to avoid needing parentheses to express its reciprocal of 1e-9.