Skip to content
Ryan Durham edited this page Nov 26, 2021 · 3 revisions

An XDR floating point number is encoded into four bytes using the IEEE standard for single precision floating point numbers.

To encode a single precision floating point number:

use StageRightLabs\PhpXdr\XDR;

// Encode
$xdr = XDR::fresh()->write(3.1425, XDR::FLOAT);

To decode a single precision floating point number:

use StageRightLabs\PhpXdr\XDR;
$xdr = XDR::fresh()->write(3.1415, XDR::FLOAT);

// Decode
$float = $xdr->read(XDR::FLOAT); // ~3.1415

NB: It is likely that you will run into precision errors when decoding floating point values: https://floating-point-gui.de/errors/comparison/