PHP code example of danack / float-hex

1. Go to this page and download the library: Download danack/float-hex library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

danack / float-hex example snippets



function FloatHex\floathex;
use function FloatHex\floathex32;
use function FloatHex\float_compare;

$value = 1.2345;

echo floathex($value) . "\n";
// Output: 3ff3c083126e978d

echo floathex32($value) . "\n";
// Output: 3f9e0419

echo float_compare(1.2345, 1.234500000001);
// Output:
// ┌──────┬─────────────┬──────────────────────────────────────────────────────┐
// │ Sign │ Exponent    │ Mantissa                                             │
// │    0 │ 01111111111 │ 0011110000001000001100010010011011101001011110001101 │
// │    0 │ 01111111111 │ 0011110000001000001100010010011011101010100100100101 │
// │    - │ ----------- │ --------------------------------------xxxxx-x-x-x--- │
// └──────┴─────────────┴──────────────────────────────────────────────────────┘




echo float_compare(0.3, 0.1 + 0.2);


echo number_format(1.22,  64);

// Output is:
// 1.2199999999999999733546474089962430298328399658203125000000000000