3v4l.org

run code in 500+ PHP versions simultaneously
<?php // distance between two 2D points $x1 = 3; $y1 = 4; $x2 = 7; $y2 = 1; $dist = hypot($x2 - $x1, $y2 - $y1); // 5.0 // why not just sqrt(($dx)**2 + ($dy)**2)? // because hypot() avoids intermediate overflow // QUICK TIP STRAIGHT FROM GAME DEV: sometimes you only want to *compare* distances, and // square root is SLOW // in this case, just compare squared values, it's equivalent! $dx1 = $x2 - $x1; $dy1 = $y2 - $y1; $dist1Sq = $dx1 * $dx1 + $dy1 * $dy1; // some other points in space... $dist2Sq = $dx2 * $dx2 + $dy2 * $dy2; if ($dist1Sq < $dist2Sq) { // squared value compared, way faster without square root! echo "Point 2 is closer to Point 1\n"; } else { echo "Point 3 is closer to Point 1\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Aacol
function name:  (null)
number of ops:  29
compiled vars:  !0 = $x1, !1 = $y1, !2 = $x2, !3 = $y2, !4 = $dist, !5 = $dx1, !6 = $dy1, !7 = $dist1Sq, !8 = $dist2Sq, !9 = $dx2, !10 = $dy2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                       !0, 3
          1        ASSIGN                                                       !1, 4
    5     2        ASSIGN                                                       !2, 7
          3        ASSIGN                                                       !3, 1
    7     4        INIT_FCALL                                                   'hypot'
          5        SUB                                                  ~15     !2, !0
          6        SEND_VAL                                                     ~15
          7        SUB                                                  ~16     !3, !1
          8        SEND_VAL                                                     ~16
          9        DO_ICALL                                             $17     
         10        ASSIGN                                                       !4, $17
   15    11        SUB                                                  ~19     !2, !0
         12        ASSIGN                                                       !5, ~19
   16    13        SUB                                                  ~21     !3, !1
         14        ASSIGN                                                       !6, ~21
   17    15        MUL                                                  ~23     !5, !5
         16        MUL                                                  ~24     !6, !6
         17        ADD                                                  ~25     ~23, ~24
         18        ASSIGN                                                       !7, ~25
   20    19        MUL                                                  ~27     !9, !9
         20        MUL                                                  ~28     !10, !10
         21        ADD                                                  ~29     ~27, ~28
         22        ASSIGN                                                       !8, ~29
   22    23        IS_SMALLER                                                   !7, !8
         24      > JMPZ                                                         ~31, ->27
   23    25    >   ECHO                                                         'Point+2+is+closer+to+Point+1%0A'
   22    26      > JMP                                                          ->28
   25    27    >   ECHO                                                         'Point+3+is+closer+to+Point+1%0A'
   26    28    > > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
147.84 ms | 3472 KiB | 14 Q