3v4l.org

run code in 500+ 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 = 53
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 53
Branch analysis from position: 3
2 jumps found. (Code = 43) Position 1 = 45, Position 2 = 49
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 53
filename:       /in/GoZaF
function name:  (null)
number of ops:  55
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, ->53
          2    > > FE_FETCH_R                                                   $4, !1, ->53
   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        FRAMELESS_ICALL_2                strpos              ~12     !1, '.'
         20        ADD                                                  ~13     ~12, 1
         21        SEND_VAL                                                     ~13
         22        DO_ICALL                                             $14     
         23        ECHO                                                         $14
         24        ECHO                                                         '+zero%28s%29%0A'
   35    25        ROPE_INIT                                         3  ~16     '%28PMA%29+'
         26        ROPE_ADD                                          1  ~16     ~16, !1
         27        ROPE_END                                          2  ~15     ~16, '+has+'
         28        ECHO                                                         ~15
         29        INIT_FCALL                                                   'preg_match_all'
         30        SEND_VAL                                                     '%7E%28%3F%3A%5C.%7C%5CG%28%3F%21%5E%29%290%7E'
         31        SEND_VAR                                                     !1
         32        DO_ICALL                                             $18     
         33        ECHO                                                         $18
         34        ECHO                                                         '+zero%28s%29%0A'
   36    35        ROPE_INIT                                         3  ~20     '%28PA%29+'
         36        ROPE_ADD                                          1  ~20     ~20, !1
         37        ROPE_END                                          2  ~19     ~20, '+has+'
         38        ECHO                                                         ~19
         39        INIT_FCALL                                                   'preg_match'
         40        SEND_VAL                                                     '%7E%5C.%5CK0%2B%7E'
         41        SEND_VAR                                                     !1
         42        SEND_REF                                                     !2
         43        DO_ICALL                                             $22     
         44      > JMPZ                                                         $22, ->49
         45    >   FETCH_DIM_R                                          ~23     !2, 0
         46        STRLEN                                               ~24     ~23
         47        QM_ASSIGN                                            ~25     ~24
         48      > JMP                                                          ->50
         49    >   QM_ASSIGN                                            ~25     0
         50    >   ECHO                                                         ~25
         51        ECHO                                                         '+zero%28s%29%0A'
   32    52      > JMP                                                          ->2
         53    >   FE_FREE                                                      $4
   38    54      > 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.5.0


preferences:
169.23 ms | 2713 KiB | 20 Q