-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to convert numbers between double and decimal in the same way as node.js, python3, ruby, rust or so #172
Comments
It's not zhat easy: insert 191/200 in Oracle DB into a num NUMBER column. I don't think that hiding this in a driver would do any good... |
@tgulacsi I think that the inserted value is not 0.955. |
You're right, it depends on the column's data type - NUMBER works as expected,
PL/SQL Developer (Delphi):
SQL*Plus:
So yes, I've also fallen: it's only the displaying library's error. |
I think that the feature is useful for node-oracledb. But it isn't for cx_Oracle (if I don't misunderstand this) and rust-oracle because they use Well, I thought that cx_Python also used |
We'll definitely evaluate it. |
Request in short
Could you add an option to use
dtoa.c
by David M. Gay or similar code to convert values betweenDPI_NATIVE_TYPE_DOUBLE
andDPI_ORACLE_TYPE_NUMBER
.dtoa.c
is used by ruby and python3.Though I don't know whether node.js uses
dtoa.c
or not, ECMAScript definition suggests to referdtoa.c
as follows.Rust uses same algorithm with
dtoa.c
as a fallback of Grisu algorithm.I think it can be included in ODPI-C because MySQL includes code based on
dtoa.c
.Background
As far as I checked, node.js, python3, ruby and rust seem to convert numbers between double and decimal in the same way.
Here is a python3 code to check above. Any value between 2.3 and 2.30000000000001 is converted to string differently. No round trip errors are displayed. I made similar codes for node.js, ruby, rust and go. They printed exactly same results.
I think that this issue is resolved when decimal to binary conversion is exactly same with ODPI-C and languages using ODPI-C.
A floating point number 2.3 in node.js, python3, ruby and rust consists of bits
100000000000010011001100110011001100110011001100110011001100110
.It is inserted to an Oracle number column as
2.3
. But when the column is fetched usingDPI_NATIVE_TYPE_DOUBLE
, the fetched value consists of bits100000000000010011001100110011001100110011001100110011001100111
(the last one bit is set.) It is displayed as2.3000000000000003
because different double values are converted to different string values in the languages. If ODPI-C converts Oracle number, represented as decimal number, to floating point number as the languages do, it is displayed as2.3
.FYI
Ruby includes
dtoa.c
fromutil.c
as follows to rename public function names.In https://github.com/ruby/ruby/blob/v3_1_1/util.c#L610-L616:
ruby_strtod
is used to convert string to double.ruby_dtoa
is used to convert double to string.The text was updated successfully, but these errors were encountered: