TO_BINARY_FLOAT Function Design

1. Purpose

TO_BINARY_FLOAT reuses BINARY_FLOAT input and numeric conversion routines and the TO_NUMBER format parser. Direct floating-point text retains support for scientific notation and special values.

For usage examples, see TO_BINARY_FLOAT Function.

2. Implementation

2.1. Code Organization

Function registration and the C entry point reside in contrib/ivorysql_ora/src/builtin_functions/. Type conversion resides in the extension’s src/datatype/. Format parsing resides in src/backend/utils/adt/.

File Responsibility

builtin_functions--1.0.sql

Registers text and numeric overloads and their return type

numeric_datatype_functions.c

Implements the C entry point and both text conversion paths

binary_float.c

Provides type input and NUMBER conversion

formatting.c

Provides shared format parsing and leading-space handling

2.2. Overloads and Conversion Paths

sys.to_binary_float registers (text), (text, text), and three numeric overloads. The text overloads share the C entry point ora_to_binary_float(), which checks the argument count for a format model. SQL wrappers use existing casts from NUMBER and the other binary floating-point type, and return same-type input directly. All overloads are STRICT.

text -> binary_float_in() -> BINARY_FLOAT
text + format -> ora_to_number_internal() -> number_binary_float() -> BINARY_FLOAT

The one-argument path converts the text to a C string and calls binary_float_in(). The formatted path obtains a Numeric from ora_to_number_internal() and calls number_binary_float(). The C entry point returns SQL NULL when the format parser returns a null result.

2.3. Leading Spaces in Formatted Input

The shared parser skips leading spaces before any numeric content is read, so those spaces do not consume digit positions marked by 9. This preserves the fractional part of 1234.5 with leading spaces under the model 9999.9. After numeric content begins, parsing continues according to the model.

3. Validation

The extension’s sql/ora_binary_float.sql and expected/ora_binary_float.out cover plain text, scientific notation, format models, leading spaces, empty formats, special values, and numeric overloads. Run the following regression group against an instance with the matching built and installed extension.

make -C contrib/ivorysql_ora oracle-installcheck ORA_REGRESS=ora_binary_float