[Maria-developers] Formatting rules for double => varchar assignment
Hi MariaDB Developers, I have an application which depends on the formatting MariaDB applies to a double when assigned to a char/varchar column of different lengths, and am trying to reproduce the behaviour in PHP. I have gotten some way but just can't seem to get the rules right. I'm having trouble finding a specification for this in the docs or the code that is responsible for this in the MariaDB source. Can someone point me in the right direction? Thanks
Hi, Jesse! On Jun 23, Jesse Schalken wrote:
Hi MariaDB Developers,
I have an application which depends on the formatting MariaDB applies to a double when assigned to a char/varchar column of different lengths, and am trying to reproduce the behaviour in PHP. I have gotten some way but just can't seem to get the rules right.
I'm having trouble finding a specification for this in the docs or the code that is responsible for this in the MariaDB source. Can someone point me in the right direction?
It is based on the popular dtoa.c by David M. Gay. The original source code is here: http://www.netlib.org/fp/dtoa.c The math is explained here: http://ampl.com/REFS/rounding.pdf Regards, Sergei Chief Architect MariaDB and security@mariadb.org
On 23 Jun 2016 1:41 am, "Sergei Golubchik" <serg@mariadb.org> wrote:
Hi, Jesse!
It is based on the popular dtoa.c by David M. Gay. The original source code is here: http://www.netlib.org/fp/dtoa.c The math is explained here: http://ampl.com/REFS/rounding.pdf
Thanks Sergei,
From what I can tell that library is focused on extracting the decimal digits from a double. I actually managed to do that part (in a slightly hackish way) using PHP's sprintf(), and the digits themselves do match.
Where I'm stuck is how MariaDB decides between scientific and regular decimal notation. The number of significant digits, their position relative to the decimal point, and the target column length all seem to play a part, but I can't deduce exactly how.
Regards, Sergei Chief Architect MariaDB and security@mariadb.org
Hi, Jesse! On Jun 23, Jesse Schalken wrote:
Where I'm stuck is how MariaDB decides between scientific and regular decimal notation. The number of significant digits, their position relative to the decimal point, and the target column length all seem to play a part, but I can't deduce exactly how.
This is done in our my_gcvt() function. Its goal is to minimize the information loss, given the limited target column length. There are different cases to consider, comments in the function explain some of them. Regards, Sergei Chief Architect MariaDB and security@mariadb.org
On 23 Jun 2016 4:02 am, "Sergei Golubchik" <serg@mariadb.org> wrote:
Hi, Jesse!
This is done in our my_gcvt() function.
Its goal is to minimize the information loss, given the limited target column length. There are different cases to consider, comments in the function explain some of them.
That's the code I'm looking for! It's fascinating reading code that I've spent much time trying to replicate the behaviour of. I got it pretty close. Thanks!
Regards, Sergei Chief Architect MariaDB and security@mariadb.org
participants (2)
-
Jesse Schalken
-
Sergei Golubchik