CAST_TO_BINARY_FLOAT

2023-10-24 09:23:03  Updated

The CAST_TO_BINARY_FLOAT function converts a BINARY_FLOAT value in the binary RAW representation into a BINARY_FLOAT value.

Syntax

UTL_RAW.CAST_TO_BINARY_FLOAT (
   r          IN RAW
   endianess  IN PLS_INTEGER DEFAULT 1)
RETURN BINARY_FLOAT;

Parameters

Parameter Description
r The binary representation of BINARY_FLOAT.
endianess The BINARY_INTEGER value that represents big_endian or little-endian. The default value is big_endian.

Return values

The BINARY_FLOAT value is returned.

Usage notes

  • If the RAW parameter exceeds 4 bytes in length, only the first 4 bytes are used and the remaining bytes are ignored. If the result is -0, +0 is returned. If the result is NaN, the return value is BINARY_FLOAT_NAN.

  • If the RAW parameter is less than 4 bytes in length, the VALUE_ERROR exception is thrown.

  • The following list shows the mapping between a 4-byte BINARY_FLOAT value and the IEEE 754 single-precision format:

    byte 0: bit 31–bit 24
    byte 1: bit 23–bit 16
    byte 2: bit 15–bit 8
    byte 3: bit 7–bit 0
    
  • The endianess parameter describes how BINARY_FLOAT bytes are mapped to RAW bytes, as shown in the following matrix. rb0–rb3 are the RAW bytes, and fb0–fb3 are the BINARY_FLOAT bytes.

    endianess rb0 rb1 rb2 rb3
    big_endian fb0 fb1 fb2 fb3
    little_endian fb3 fb2 fb1 fb0
  • For machine-endian, the 4 bytes of the RAW parameter are copied directly into the return BINARY_FLOAT value. Passing big_endian on a big-endian machine has the same effect as passing little_endian on a little-endian machine.

Examples

obclient> SELECT UTL_RAW.CAST_TO_BINARY_FLOAT('13579BD') FROM DUAL;
+-----------------------------------------+
| UTL_RAW.CAST_TO_BINARY_FLOAT('13579BD') |
+-----------------------------------------+
|                         3.33317925E-038 |
+-----------------------------------------+
1 row in set

obclient> SELECT UTL_RAW.CAST_TO_BINARY_FLOAT('13579BD', 2) FROM DUAL;
+-------------------------------------------+
| UTL_RAW.CAST_TO_BINARY_FLOAT('13579BD',2) |
+-------------------------------------------+
|                          -6.08415641E-002 |
+-------------------------------------------+
1 row in set

obclient> SELECT UTL_RAW.CAST_TO_BINARY_FLOAT('13579BD', 3) FROM DUAL;
+-------------------------------------------+
| UTL_RAW.CAST_TO_BINARY_FLOAT('13579BD',3) |
+-------------------------------------------+
|                          -6.08415641E-002 |
+-------------------------------------------+
1 row in set

Contact Us