3v4l.org

run code in 300+ PHP versions simultaneously
<?php function mathematical_zeros_after_dot($float) { $float = abs($float); // remove any signs $float -= (int)$float; // remove whole numbers from float if ($float == 0) { return "Rendered as 0"; } $max = 20; for ($x = 0; $x < $max; ++$x) { $float *= 10; if ($float >= 1) { return $x; } } return "$max {exceeded}"; } $floats = [ 25.000000000022, // 10 0.0000062, // 5 0.020320, // 1 .505000, // 0 0, // 0 .000507, // 3 -.002009, // 2 1000, // 0 0.00, // 0 1 // 0 -1.0000000000004000004, // 12 981.0000000000000000000004000004 // 21 ]; foreach ($floats as $float) { echo "(Math) {$float} has " , mathematical_zeros_after_dot($float) , " zero(s)\n"; echo "Barmar {$float} has " , strspn($float, "0", strpos($float, ".")+1) , " zero(s)\n"; echo "(PMA) {$float} has " , preg_match_all('~(?:\.|\G(?!^))0~', $float) , " zero(s)\n"; echo "(PA) {$float} has " , (preg_match('~\.\K0+~', $float, $match) ? strlen($match[0]) : 0) , " zero(s)\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 56
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 56
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 52
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 53
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 56
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 56
filename:       /in/GoZaF
function name:  (null)
number of ops:  58
compiled vars:  !0 = $floats, !1 = $float, !2 = $match
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   ASSIGN                                                   !0, <array>
   32     1      > FE_RESET_R                                       $4      !0, ->56
          2    > > FE_FETCH_R                                               $4, !1, ->56
   33     3    >   ROPE_INIT                                     3  ~6      '%28Math%29+'
          4        ROPE_ADD                                      1  ~6      ~6, !1
          5        ROPE_END                                      2  ~5      ~6, '+has+'
          6        ECHO                                                     ~5
          7        INIT_FCALL                                               'mathematical_zeros_after_dot'
          8        SEND_VAR                                                 !1
          9        DO_FCALL                                      0  $8      
         10        ECHO                                                     $8
         11        ECHO                                                     '+zero%28s%29%0A'
   34    12        ROPE_INIT                                     3  ~10     'Barmar+'
         13        ROPE_ADD                                      1  ~10     ~10, !1
         14        ROPE_END                                      2  ~9      ~10, '+has+'
         15        ECHO                                                     ~9
         16        INIT_FCALL                                               'strspn'
         17        SEND_VAR                                                 !1
         18        SEND_VAL                                                 '0'
         19        INIT_FCALL                                               'strpos'
         20        SEND_VAR                                                 !1
         21        SEND_VAL                                                 '.'
         22        DO_ICALL                                         $12     
         23        ADD                                              ~13     $12, 1
         24        SEND_VAL                                                 ~13
         25        DO_ICALL                                         $14     
         26        ECHO                                                     $14
         27        ECHO                                                     '+zero%28s%29%0A'
   35    28        ROPE_INIT                                     3  ~16     '%28PMA%29+'
         29        ROPE_ADD                                      1  ~16     ~16, !1
         30        ROPE_END                                      2  ~15     ~16, '+has+'
         31        ECHO                                                     ~15
         32        INIT_FCALL                                               'preg_match_all'
         33        SEND_VAL                                                 '%7E%28%3F%3A%5C.%7C%5CG%28%3F%21%5E%29%290%7E'
         34        SEND_VAR                                                 !1
         35        DO_ICALL                                         $18     
         36        ECHO                                                     $18
         37        ECHO                                                     '+zero%28s%29%0A'
   36    38        ROPE_INIT                                     3  ~20     '%28PA%29+'
         39        ROPE_ADD                                      1  ~20     ~20, !1
         40        ROPE_END                                      2  ~19     ~20, '+has+'
         41        ECHO                                                     ~19
         42        INIT_FCALL                                               'preg_match'
         43        SEND_VAL                                                 '%7E%5C.%5CK0%2B%7E'
         44        SEND_VAR                                                 !1
         45        SEND_REF                                                 !2
         46        DO_ICALL                                         $22     
         47      > JMPZ                                                     $22, ->52
         48    >   FETCH_DIM_R                                      ~23     !2, 0
         49        STRLEN                                           ~24     ~23
         50        QM_ASSIGN                                        ~25     ~24
         51      > JMP                                                      ->53
         52    >   QM_ASSIGN                                        ~25     0
         53    >   ECHO                                                     ~25
         54        ECHO                                                     '+zero%28s%29%0A'
   32    55      > JMP                                                      ->2
         56    >   FE_FREE                                                  $4
   38    57      > RETURN                                                   1

Function mathematical_zeros_after_dot:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 10
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 13
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 17
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 13
Branch analysis from position: 20
Branch analysis from position: 13
filename:       /in/GoZaF
function name:  mathematical_zeros_after_dot
number of ops:  24
compiled vars:  !0 = $float, !1 = $max, !2 = $x
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
    3     1        INIT_FCALL                                               'abs'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $3      
          4        ASSIGN                                                   !0, $3
    4     5        CAST                                          4  ~5      !0
          6        ASSIGN_OP                                     2          !0, ~5
    5     7        IS_EQUAL                                                 !0, 0
          8      > JMPZ                                                     ~7, ->10
    6     9    > > RETURN                                                   'Rendered+as+0'
    8    10    >   ASSIGN                                                   !1, 20
    9    11        ASSIGN                                                   !2, 0
         12      > JMP                                                      ->18
   10    13    >   ASSIGN_OP                                     3          !0, 10
   11    14        IS_SMALLER_OR_EQUAL                                      1, !0
         15      > JMPZ                                                     ~11, ->17
   12    16    > > RETURN                                                   !2
    9    17    >   PRE_INC                                                  !2
         18    >   IS_SMALLER                                               !2, !1
         19      > JMPNZ                                                    ~13, ->13
   15    20    >   NOP                                                      
         21        FAST_CONCAT                                      ~14     !1, '+%7Bexceeded%7D'
         22      > RETURN                                                   ~14
   17    23*     > RETURN                                                   null

End of function mathematical_zeros_after_dot

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.41 ms | 1013 KiB | 19 Q