g | x | w | all
Bytes Lang Time Link
019JavaScript ES6170519T142130ZArnauld
006jamforth231109T122418Zallisonl
008TIBasic231107T211753ZYouserna
002Japt v2.0a0230718T150018ZLuis fel
001Vyxal l231106T122758Zlyxal
007Uiua231104T185420Zchunes
025Raku230718T195021Zbb94
005Thunno 2230718T141404ZThe Thon
007K ngn/k201222T195026Zcoltim
033Java 8170519T214856ZKevin Cr
005Vyxal210416T070157Zlyxal
026Factor210416T023016Zchunes
026Excel210416T013752ZAxuary
080Make210416T000713Zcnamejj
046PowerShell Core210415T213149ZJulian
007Julia210413T165926ZMarcMush
038R210411T104625ZDominic
014Pip210107T053733ZParker K
033AWK210107T043137ZPedro Ma
024Perl 5 Minteger p180422T044457ZXcali
030ARM Thumb2 no div instruction201225T054039ZEasyasPi
007APL Dyalog Unicode201222T192213ZKamila S
012Gol><>180503T071954ZBubbler
040R180503T031054ZJayCe
010Pyth180422T215824Zhakr14
041Rust180422T074158ZArcterus
053@yBASIC180422T062043Z12Me21
027Ruby170520T093927ZEric Dum
013Pari/GP170520T041943Zalephalp
008Actually170520T015627Zuser4594
006bc170519T210438Zeush77
001dc170519T204614Zeush77
027C170519T194243ZKhaled.K
048Python 2170519T134425ZFelipe N
033Ruby170519T185951ZValue In
nan170519T181818Zuser6213
050Bash170519T173256Zmarcosm
025QBIC170519T161608Zsteenber
051PowerShell170519T142255Zcolsw
005Chaincode170519T145131ZLinnea G
023PHP170519T144408ZJör
016Alice170519T143832ZLeo
003Japt170519T140052ZLuke
027Octave170519T142730ZLuis Men
040Lua170519T142711ZFelipe N
056C#170519T135237ZTheLetha
005Jelly170519T140047Zuser6318
002Jelly170519T135459ZLuis Men
00605AB1E170519T135107ZRiley
005MATL170519T135121ZLuis Men
030Python 2170519T134820ZLeaky Nu
013Mathematica170519T134514ZMartin E
041S.I.L.O.S170519T134423ZLeaky Nu

JavaScript (ES6), 19 bytes

f=n=>n&&f(n/10|0)+1

Try it online!

Or 18 bytes with BigInts, as suggested by @Lucenaposition.

jamforth, 6 bytes

UWIDTH

I'm not sure why gforth doesn't have UWIDTH. It's actually really useful.

This solution also works in arbitrary bases.

TI-Basic, 9 8 bytes

int(log(1+10abs(Ans

Takes input in Ans.

-1 byte thanks to MarcMush.

Japt v2.0a0, 3 2 bytes

Split on each number and get the length. Is this ok? I'm not using any string method implicitly

thanks @The Empty String Photographer

ìl

Try it

Vyxal l, 1 byte

ȧ

Try it Online!

This is why restricting built-ins is a bad idea. The l flag outputs the length of the top of the stack implicitly, which I don't think is a "function" - it's a feature of the language variant, not a function.

The ȧ simply gets the absolute value because - is counted in the size.

Uiua, 7 bytes

⌈ₙ10+1⌵

Try it!

⌈ₙ10+1⌵
      ⌵  # absolute value
    +1   # increment
 ₙ10     # log base ten
⌈        # ceiling

Raku, 25 bytes

{0 max.abs.log10.floor+1}

Try it online!

Thunno 2, 5 bytes

A⁺Ælṃ

Try it online!

A⁺Ælṃ  # Implicit input
A      # Absolute value
 ⁺     # Increment it
  Æl   # Log base 10
    ṃ  # Ceiling
       # Implicit output

K (ngn/k), 10 9 7 bytes

-3 bytes from @ngn (see Am I an insignificant array?)

#10\#!:

Try it online!

A solution using $ instead of 10\ save two bytes, but may be invalid given the question's rules.

Java 8, 61 59 39 37 33 bytes

n->(int)Math.log10(n<0?-n:n+.5)+1

-4 bytes thanks to @MarkJeronimus.

Try it online.

Explanation:

n->            // Method with integer as both parameter and return-type
  (int)        //  Convert the following double to an integer (truncating its decimals):
    Math.log10(//   The log_10 of:
      n<0?     //    If the input is negative:
          -n   //     Use its absolute value
         :     //    Else:
          n+.5)//     Add 0.5 to the input instead
  +1           //  And add 1 to the result at the end

Vyxal, 5 bytes

ȧ›∆τ⌈

Try it Online!

Thanks to the 05AB1E answer for providing me with an algorithm to port.

Explained

ȧ›∆τ⌈
ȧ›      # abs(input) + 1
  ∆τ    # log_10(↑)
    ⌈   # ceil(↑)

Factor, 26 bytes

[ abs log10 >integer 1 + ]

Try it online!

Excel, 26 bytes

=INT(LOG(A1^2+(A1=0))/2)+1

Log of the number squared / 2 is 1 byte shorter than ABS

Make, 80 bytes

$(N):
ifeq ($(N),0)
	@echo 0
else
	@expr 1 + $(shell make N=$$(($(N)/10)))
endif

Try it online!

I'm posting this entry for two reasons...

First, it's a ridiculous way to get the number of digits. :) It's recursively calling make, each time dividing the number by 10, and counting how many time that happens.

Second, it works on my Linux test system from the commandline (which is using GNU Make 4.1) but will not work at all on TIO (which appears to be using GNU Make 4.2.1). So I'm really curious about that and would like to know if it works for other people? It might just be that I don't know how to translate things like:

~/work/code-golf$ make N=888
3

to TIO's input format syntax?

PowerShell Core, 46 bytes

param($a)for($s=0;$a){$s+=!!($a=[int]$a/10)}$s

Implementation Details

param($a)              # Defines the input parameter
for($s=0;$a){          # Initialise the result to 0 and iterates while the parameter is not 0 
$s+=!!($a=[int]$a/10)  # Divides the parameter by 10 and increment the result variable
                       # by one if the result is not 0
}$s                    # Returns the result

Try it online!

Julia, 7 bytes

ndigits

Try it online!

R, 38 bytes

f=function(x)`if`(x^2<100,1,1+f(x/10))

Try it online!

Unusually for R, a recursive function seems to be shorter here than the previous answer using built-in functions (although this is mostly gained simply because we can skip abs(x) by using x^2<100 as a condition instead)...

Pip, 14 bytes

LNABq/LNt//1+1

https://tio.run/##K8gs@P/fx8/RqVDfx69EX99Q2/D/f0MDczNjC1NjCwA

Explanation

LN              natural log of...      (change of base becasue this is the only log function they had)
  ABq           the absolute value of the input...
     /          divided by...
      LNt       the natural log of 10...   (change of base)
         //1    integer divided by 1 (no floor function)
            +1  added to 1

This was inspired by the Chaincode solution.

This could probably be optimized.

AWK, 33 bytes

$1=int(log(($1?$1^2:1)^.5)/2.3)+1

Try it online!

Basically, this will print the integer part of the log base 10 of the input, plus one. 2.3 is a working approximation of natural log of 10. To deal with negative numbers, it takes the square root of the power of two. If input is zero, returns 1 instead, so the pattern is different from 0, which would return false and would not be printed. Too many necessary workarounds.

Perl 5 -Minteger -p, 26 24 bytes

1while++$\*abs($_/=10)}{

Try it online!

ARM Thumb-2 (no div instruction, no libgcc), 30 bytes

Raw machine code:

2800 d00b bfb8 4240 2201 2100 3101 380a
dafc 3201 0008 280a daf7 0010 4770     

Uncommented assembly:

        .syntax unified
        .globl count_digits
        .thumb
        .thumb_func
count_digits:
        cmp     r0, #0
        beq     .Lret
        it      lt
        neglt   r0, r0
        movs    r2, #1
.Lcountloop:
        movs    r1, #0
.Ldivloop:
        adds    r1, #1
        subs    r0, #10
        bge     .Ldivloop
.Ldivloop_end:
        adds    r2, #1
        movs    r0, r1
        cmp     r0, #10
        bge     .Lcountloop
.Lcountloop_end:
        movs    r0, r2
.Lret:
        bx      lr

Returns 0 if 0.

Explanation

C function signature:

int32_t count_digits(int32_t val);

First, we compare val to zero.

If it is zero, we return zero. If it is less than zero, we negate it.

count_digits:
        cmp     r0, #0
        beq     .Lret
        it      lt
        neglt   r0, r0

Set up our digit counter for the outer loop.

        movs    r2, #1

Now, a naïve subtraction based division loop

        movs    r1, #0
.Ldivloop:
        adds    r1, #1
        subs    r0, #10
        bge     .Ldivloop

Increment the digits counter, then loop to the outer loop if we are still more than 10.

.Ldivloop_end:
        adds    r2, #1
        movs    r0, r1
        cmp     r0, #10
        bge     .Lcountloop

Move the result into the return register and return.

.Lcountloop_end:
        movs    r0, r2
.Lret:
        bx      lr

APL (Dyalog Unicode), 7 bytes

⌈10⍟1+|

Try it online!

Explanation:

⌈10⍟1+|
⌈        ⍝ round up the
 10⍟     ⍝ log10 of...
    1+   ⍝ incremented
      |  ⍝ absolute value of input

If format is allowed: 4 bytes - ≢⍕∘|

Gol><>, 12 bytes

SA:z+aSLS(PB

Try it online!

Example full program & How it works

1AGIE;GN
SA:z+aSLS(PB

1AGIE;GN
1AG       Register row 1 as function G
   IE;    Take input as int, halt if EOF
      GN  Call G and print the result as int

SA:z+aSLS(PB
SA            Absolute value
  :z+         Add 1 if zero
     aSL      Take log 10
        S(    Floor
          PB  Increment and return

Many math functions are prefixed with S, which made the code longer.

Adding 0.9 unconditionally (9a,+) and using ceiling (S)) is also possible with same byte count. Zero input yields 0 in this case.

R, 40 bytes

function(x)max(ceiling(log10(abs(x))),0)

Try it online!

Pyth, 10 bytes

.xhs.l.aQT

Test suite

Explanation:
.xhs.l.aQT  # Code
.xhs.l.aQTQ # With implicit variables
            # Print (implicit):
    .l   T  #   the log base 10 of:
      .aQ   #    the absolute value of the input
   s        #   floored
  h         #   plus 1
.x        Q #  unless it throws an error, in which case the input
Python 3 translation:
import math
Q=eval(input())
try:
    print(int(math.log(abs(Q),10))+1)
except:
    print(Q)

Rust, 41 bytes

fn f(n:i32)->u8{n!=0&&return f(n/10)+1;0}

Try it online!

@yBASIC, 53 bytes.

_#=@_>.@_
_%=_%/(_#*_#+!.)_=_+!.GOTO(@_)+"_"*!_%@__?_

Input should be stored in variable _%

Ruby, 27 bytes

f=->x{x==0?0:1+f[x.abs/10]}

As a test:

tests = [[-45 , 2],
         [1254 , 4],
         [107638538 , 9],
         [-20000 , 5],
         [0 , 0 ],
         [-18 , 2]]

tests.each do |i, o|
  p f.call(i) == o
end

It outputs:

true
true
true
true
true
true

Pari/GP, 13 bytes

n->#digits(n)

Try it online!

Actually, 8 bytes

;0=+A╥Lu

Try it online!

Explanation:

;0=+A╥Lu
;0=       is input equal to 0?
   +      add 1 if input is 0, else add 0
    A     absolute value
     ╥L   log base 10, floor
       u  increment

This program effectively calculates floor(log10(x))+1. To deal with log(0) being undefined (actually it returns (-inf+nanj) which is a special way of saying it's undefined), the input is incremented if it is 0 prior to computing the length. Thus, 0 is considered to have a length of 1.

bc, 6 bytes

length

Built-in function.

dc, 1 byte

Z

Try it online!


Not using a builtin, 18 bytes:

[d10/d0!=F]dsFxz1-

Try it online!

C, 27 bytes

Try Online

f(n){return n?1+f(n/10):0;}

C (gcc), 22 bytes

f(n){n=n?1+f(n/10):0;}

Using math, 29 bytes

f(n){return 1+log10(abs(n));}

Python 2, 48 bytes

-3 thanks to ovs -1 thanks to pizzapants

lambda x:math.log10(abs(10*x)+1)//1
import math

Try it online!

Ruby, 33 bytes

->x{1+Math.log10(x.abs+0.1).to_i}

Try it online!

My answer from the other challenge still works:

Brachylog, 1 byte

l

Try it online!

The l builtin is overloaded, but on integers, it takes the number of digits of the integer, ignoring sign.

Bash, 50 bytes

a=$1;until [ $a -eq 0 ];{ let i++ a=a/10;};echo $i

Try it online!

No string/array command, only count digits by integer division.

QBIC, 25 bytes

≈abs(:)>=1|b=b+1┘a=a/z}?b

This divides the input by 10, and keeps track of how many times we can do this until N < 1.

Explanation:

≈abs(:)>=1| : gets cmd line input, 
            ≈ starts a while loop,
            abs() is literal QBasic code and is for cases with negative n
            | is the terminator to the WHILE-condition
b=b+1       Keep track of the # of divisions        
┘           Syntactic line break
a=a/z       Divide a by 10 (z==10 in QBIC)
}           End WHILE-loop body
?b          PRINT b

PowerShell, 52 51 Bytes

$m=[math];$m::Floor($m::Log10($m::Abs($args[0])))+1

Thanks to Felipe for both fixing the Issue with Log10, and providing a 1byte save.

Any System.Math calls are extremely expensive in PowerShell.

Uses the method of getting the Log10 of the Abs Value of the input, and rounding that up.

Chaincode, 5 bytes

pqL_+

Note: This is exactly the same code as that from the other challenge

Explanation

pqL_+ print(
    +   succ(
   _      floor(
  L        log_10(
pq           abs(
               input())))))

PHP, 23 Bytes

<?=-~log10(abs($argn));

Try it online!

Alice, 16 bytes

/O
\I@/Hwa:].$Kq

Try it online!

Explanation

/O
\I@/...

This is simply a framework for numerical input→mathematical processing→numerical output.

The rest of the code is the real algorithm:

Hwa:].$Kq
H            Compute absolute value
 w   .$K     While the result is not zero do:
  a:           divide the number by 10
    ]          move the tape head one cell forward
        q    Get the position of the tape head

Japt, 5 3 bytes

ì l

Try it online!

Octave, 27 bytes

@(x)fix(log10(abs(x+~x)))+1

Try it online!

Lua, 40 bytes

Port from my python answer

print(math.log10(math.abs(10*...)+1)//1)

Try it online!

C#, 49 56 bytes

namespace System.Math{n=>n==0?1:Floor(Log10(Abs(n))+1);}

Jelly, 5 bytes

A‘l⁵Ċ

Try it online!

Jelly, 3 2 bytes

1 byte saved thanks to Leaky Nun

DL

Try it online!

Explanation

 L    Length of
D     Decimal expansion of input argument. Works for negative values too

05AB1E, 6 bytes

Ä>T.nî

Try it online! or Try all tests

Ä      # Absolute value
 >     # Increment
  T.n  # Log base 10
     î # Round up

MATL, 5 bytes

|OYAn

Try it online!

Explanation

|     % Implicitly input a number. Absolute value
OYA   % Convert to array of decimal digits
n     % Length. Implicitly display

Python 2, 30 bytes

f=lambda x:x and-~f(abs(x)/10)

Try it online!

Mathematica, 13 bytes

IntegerLength

Well...

S.I.L.O.S, 41 bytes

readIO
i|
lblb
i/10
a+1
if i b
printInt a

Try it online!

Returns 1 for 0.