Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ SQL » Huge error of Postgresql! Double fields by transmission to the program lose a fractional part!
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47537 is a reply to message #47536] Thu, 26 January 2017 01:43 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

But if I start
LC_ALL=en_US.UTF-8 ./ProgramName

or
LANG=en_US.UTF-8 ./ProgramName


than all correct.

26.01.2017 03:41:15 ===start analysis===
26.01.2017 03:41:15 s = 40
26.01.2017 03:41:15 da = 40
26.01.2017 03:41:15 dS = 40
26.01.2017 03:41:15 test_format_and_lang_settings = 40.000000
26.01.2017 03:41:15 ====end analysis====
26.01.2017 03:41:15  
26.01.2017 03:41:15 ===start analysis===
26.01.2017 03:41:15 s = 269.96336996337
26.01.2017 03:41:15 da = 269.96336996337
26.01.2017 03:41:15 dS = 269.96336996337
26.01.2017 03:41:15 test_format_and_lang_settings = 269.963370
26.01.2017 03:41:15 ====end analysis====
26.01.2017 03:41:15  
26.01.2017 03:41:15 ===start analysis===
26.01.2017 03:41:15 s = 59.95115995116
26.01.2017 03:41:15 da = 59.95115995116
26.01.2017 03:41:15 dS = 59.95115995116
26.01.2017 03:41:15 test_format_and_lang_settings = 59.951160
26.01.2017 03:41:15 ====end analysis====
26.01.2017 03:41:15  


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Thu, 26 January 2017 01:50]

Report message to a moderator

Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47538 is a reply to message #47537] Thu, 26 January 2017 01:45 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

It's repeated same results on different computer (but always under UBUNTU 16.04)

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47539 is a reply to message #47538] Thu, 26 January 2017 01:57 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Postgresql (Server v. 9.5) language settings are default.



fragment of postgres config:
# These settings are initialized by initdb, but they can be changed.
lc_messages = 'ru_RU.UTF-8'			# locale for system error message
					# strings
lc_monetary = 'ru_RU.UTF-8'			# locale for monetary formatting
lc_numeric = 'ru_RU.UTF-8'			# locale for number formatting
lc_time = 'ru_RU.UTF-8'				# locale for time formatting




SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47540 is a reply to message #47539] Thu, 26 January 2017 02:04 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

I change postgresql setting to ( /etc/postgresql/9.5/main/postgresql.conf )
en_US:
# These settings are initialized by initdb, but they can be changed.
#lc_messages = 'ru_RU.UTF-8'			# locale for system error message
					# strings
#lc_monetary = 'ru_RU.UTF-8'			# locale for monetary formatting
#lc_numeric = 'ru_RU.UTF-8'			# locale for number formatting
#lc_time = 'ru_RU.UTF-8'				# locale for time formatting


lc_messages = 'en_US.UTF-8'			# locale for system error message
					# strings
lc_monetary = 'en_US.UTF-8'			# locale for monetary formatting
lc_numeric = 'en_US.UTF-8'			# locale for number formatting
lc_time = 'en_US.UTF-8'				# locale for time formatting


Result is zero!
26.01.2017 03:59:52 ===start analysis===
26.01.2017 03:59:52 s = 40
26.01.2017 03:59:52 da = 40
26.01.2017 03:59:52 dS = 40
26.01.2017 03:59:52 test_format_and_lang_settings = 40,000000
26.01.2017 03:59:52 ====end analysis====
26.01.2017 03:59:52  
26.01.2017 03:59:52 ===start analysis===
26.01.2017 03:59:52 s = 269.96336996337
26.01.2017 03:59:52 da = 269
26.01.2017 03:59:52 dS = 269.96336996337
26.01.2017 03:59:52 test_format_and_lang_settings = 269,963370
26.01.2017 03:59:52 ====end analysis====
26.01.2017 03:59:52  
26.01.2017 03:59:52 ===start analysis===
26.01.2017 03:59:52 s = 59.95115995116
26.01.2017 03:59:52 da = 59
26.01.2017 03:59:52 dS = 59.95115995116
26.01.2017 03:59:52 test_format_and_lang_settings = 59,951160
26.01.2017 03:59:52 ====end analysis====


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47541 is a reply to message #47540] Thu, 26 January 2017 02:23 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

I test timings:

Test code:
#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	double a;
	String s = "269.96336996337";
	#define LOOPS 1000000
	for(int i = 0; i < LOOPS; i++){
		RTIMING("Using atof");
		a = atof(s);
	}
	for(int i = 0; i < LOOPS; i++){
		RTIMING("Using ScanDouble");
		a = ScanDouble(s);
	}
}


TIMING results:
TIMING Using ScanDouble:  1.12 s  -  1.12 us ( 1.22 s  / 1000000 ), min:  0.00 ns, max:  1.00 ms, nesting: 1 - 1000000
TIMING Using atof     : 337.45 ms - 337.45 ns (439.00 ms / 1000000 ), min:  0.00 ns, max:  1.00 ms, nesting: 1 - 1000000

It's not dramatically slower! But standard settings (on various environments) show right results!




SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47543 is a reply to message #47536] Thu, 26 January 2017 09:09 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
OK, so it seems like the moral of the story is to never trust or use 'atof'.

Makes me want to do add to Core.h either

#define atof @ // never use atof, as it has unpredictable results


or even

#define atof Atof


Atof being U++ upcoming equivalent of atof, basically Nvl(ScanDouble(x)).

[Updated on: Thu, 26 January 2017 09:09]

Report message to a moderator

Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47544 is a reply to message #47541] Thu, 26 January 2017 14:10 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
sergeynikitin wrote on Thu, 26 January 2017 02:23
I test timings:

Test code:
#include <Core/Core.h>

using namespace Upp;

CONSOLE_APP_MAIN
{
	double a;
	String s = "269.96336996337";
	#define LOOPS 1000000
	for(int i = 0; i < LOOPS; i++){
		RTIMING("Using atof");
		a = atof(s);
	}
	for(int i = 0; i < LOOPS; i++){
		RTIMING("Using ScanDouble");
		a = ScanDouble(s);
	}
}


TIMING results:
TIMING Using ScanDouble:  1.12 s  -  1.12 us ( 1.22 s  / 1000000 ), min:  0.00 ns, max:  1.00 ms, nesting: 1 - 1000000
TIMING Using atof     : 337.45 ms - 337.45 ns (439.00 ms / 1000000 ), min:  0.00 ns, max:  1.00 ms, nesting: 1 - 1000000

It's not dramatically slower! But standard settings (on various environments) show right results!




BTW, have you tried in Release? MSC14 32-bit release I am getting:

TIMING Using ScanDouble: 120.72 ms - 120.72 ns (148.00 ms / 1000000 ), min:  0.00 ns, max:  2.00 ms, nesting: 1 - 1000000
TIMING Using atof     : 281.72 ms - 281.72 ns (309.00 ms / 1000000 ), min:  0.00 ns, max:  1.00 ms, nesting: 1 - 1000000


I really would not like U++ being slower... Smile
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47545 is a reply to message #47544] Thu, 26 January 2017 15:01 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
rc4 should have this fix. Can you check please so that we can close this issue?

Mirek
Re: Huge error of Postgresql! Double fields by transmission to the program lose a fractional part! [message #47546 is a reply to message #47545] Thu, 26 January 2017 15:25 Go to previous message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Ok, I'll ckeck it tonight (a few later).

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Previous Topic: I propose to Add Postgresql to topic header
Next Topic: How can .sch express a many-to-many relationship ?
Goto Forum:
  


Current Time: Fri Apr 19 10:47:31 CEST 2024

Total time taken to generate the page: 0.04994 seconds