DoubleToString

Programmers discuss here anything related to FreeOrion programming. Primarily for the developers to discuss.

Moderator: Committer

Message
Author
User avatar
OndrejR
Space Dragon
Posts: 339
Joined: Thu Oct 02, 2008 11:00 pm
Location: Slovakia

Re: DoubleToString

#16 Post by OndrejR »

Bullet(due to building system inconsistencies) and especially Ogre(binary graphic drivers) are not easy to build(if you have nvidia, ati and intel I don't know), but with wiki compile howto it is trivial. Problem with Debian is that until official Lenny release developers are uninterested to other things such as ogre 1.6.1.

If you want Debian package and don't want to install dependency libraries with make install, then for this purpose replace

Code: Select all

make install
with

Code: Select all

checkinstall
checkinstall creates package and install it.

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12802
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: DoubleToString

#17 Post by Geoff the Medio »

You could initialize your array of char with less code:

Code: Select all

char hprefs[] = "kMGT";
One could argue your method is clearer, though.

Looking at your power-of-ten selection, it looks like you're not considering the number of digits requested. Would your code properly handle the case of val = 12345 with 5 digits? The result should be "12345" and not "12.345k".

Having a special case check at the end for mu is rather clunky... could you not use the same structure / method to pick the string representing all the prefixes?

In

Code: Select all

mag=floor(mag+0.500);
you don't need the extra 00 after 5.

Rather than

Code: Select all

        if (integer==0) { d-=1; }
        else { d-=(floor(log10(integer))+1); }
I find this makes it clearer it's an if-else block:

Code: Select all

        if (integer == 0)
            d -=1 ;
        else
            d -= (floor(log10(integer))+1);
Also, I get some compile errors:

Code: Select all

Error	17	error C2668: 'log10' : ambiguous call to overloaded function ClientUI.cpp	806
Error	18	error C2668: 'pow' : ambiguous call to overloaded function	ClientUI.cpp	827
Error	19	error C2668: 'log10' : ambiguous call to overloaded function	ClientUI.cpp	829
Error	20	error C2668: 'log10' : ambiguous call to overloaded function	ClientUI.cpp	833
Error	21	error C2668: 'log10' : ambiguous call to overloaded function	ClientUI.cpp	838
You probably need to static_cast<double> the integers.

User avatar
francys
Space Squid
Posts: 54
Joined: Sat Oct 25, 2008 8:53 pm
Location: Victoria, BC

Re: DoubleToString

#18 Post by francys »

Looking at your power-of-ten selection, it looks like you're not considering the number of digits requested. Would your code properly handle the case of val = 12345 with 5 digits? The result should be "12345" and not "12.345k".
Good observation. 12345 is displayed as 12.345k because "prefixes" are the default choice. After all, 12.345k still shows 5 digits, so they both show the correct number of digits.
Having a special case check at the end for mu is rather clunky... could you not use the same structure / method to pick the string representing all the prefixes?
I totally agree. Originally I was displaying a u so I could get away with the more elegant solution (hence the two arrays). But with the utf-8 character I'll have to switch to the if-else structure.
Also, I get some compile errors:

Code: Select all

Error	17	error C2668: 'log10' : ambiguous call to overloaded function ClientUI.cpp	806
Error	18	error C2668: 'pow' : ambiguous call to overloaded function	ClientUI.cpp	827
Error	19	error C2668: 'log10' : ambiguous call to overloaded function	ClientUI.cpp	829
Error	20	error C2668: 'log10' : ambiguous call to overloaded function	ClientUI.cpp	833
Error	21	error C2668: 'log10' : ambiguous call to overloaded function	ClientUI.cpp	838
You probably need to static_cast<double> the integers.
I didn't get warnings or errors. But now that you're making me notice it, I'll static cast the integers.

I'm happy to correct all these things as soon as I manage to launch FO without segfaults :D

User avatar
Kuhlschrank
Space Floater
Posts: 24
Joined: Fri Mar 27, 2009 11:50 pm

Re: DoubleToString

#19 Post by Kuhlschrank »

Is this, what it's meant to look like?
Attachments
doubles.png
doubles.png (12.51 KiB) Viewed 1254 times

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12802
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: DoubleToString

#20 Post by Geoff the Medio »

Kuhlschrank wrote:Is this, what it's meant to look like?
For the values shown, that looks OK.

User avatar
Kuhlschrank
Space Floater
Posts: 24
Joined: Fri Mar 27, 2009 11:50 pm

Re: DoubleToString

#21 Post by Kuhlschrank »

I just always set the integerize parameter to false. I think the values as shown in my screenshot erroneously are set to integerize = true. Is that right?

Is THAT the problem, or didn't i get it right?

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12802
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: DoubleToString

#22 Post by Geoff the Medio »

Kuhlschrank wrote:I think the values as shown in my screenshot erroneously are set to integerize = true. Is that right?
No. 12.5 is not an integer.

User avatar
Kuhlschrank
Space Floater
Posts: 24
Joined: Fri Mar 27, 2009 11:50 pm

Re: DoubleToString

#23 Post by Kuhlschrank »

Geoff the Medio wrote:
Kuhlschrank wrote:I think the values as shown in my screenshot erroneously are set to integerize = true. Is that right?
No. 12.5 is not an integer.
Ok, i mixed the words.... i meant:
"I think the values shown in my screenshot are erroneously set to integerize = true in SVN, and so are only displayed with the 'integer part' (1k instead of 1.04k when the double value is 1043 e.g.). Is that right?"

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12802
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: DoubleToString

#24 Post by Geoff the Medio »

Kuhlschrank wrote:Ok, i mixed the words.... i meant:
"I think the values shown in my screenshot are erroneously set to integerize = true in SVN, and so are only displayed with the 'integer part' (1k instead of 1.04k when the double value is 1043 e.g.). Is that right?"
I don't know if that is why they're shown wrong in the SVN version, but if I recall correctly, that is the result that is a problem.

User avatar
Kuhlschrank
Space Floater
Posts: 24
Joined: Fri Mar 27, 2009 11:50 pm

Re: DoubleToString

#25 Post by Kuhlschrank »

Where in the code are the calls to update these resource (food, minerals...) values?

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12802
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: DoubleToString

#26 Post by Geoff the Medio »

Kuhlschrank wrote:Where in the code are the calls to update these resource (food, minerals...) values?
StatisticIcon::Refresh() in CUIControls.cpp. You'll probably need to find where those StatisticIcon are created though, since it gets the integerize parameter from the constructor.

Really, we don't need an integerize parameter at all, though.

User avatar
Kuhlschrank
Space Floater
Posts: 24
Joined: Fri Mar 27, 2009 11:50 pm

Re: DoubleToString

#27 Post by Kuhlschrank »

Geoff the Medio wrote:Really, we don't need an integerize parameter at all, though.
That's the answer for my next question... =)

So there really is NO need for this integerization?

User avatar
Kuhlschrank
Space Floater
Posts: 24
Joined: Fri Mar 27, 2009 11:50 pm

Re: DoubleToString

#28 Post by Kuhlschrank »

The Structors are in MapWnd.cpp (line 535).
Just change them to the following:

Code: Select all

    m_population = new StatisticIcon(m_btn_siterep->UpperLeft().x-LAYOUT_MARGIN-ICON_DUAL_WIDTH,GG::Y(LAYOUT_MARGIN),ICON_DUAL_WIDTH,m_turn_update->Height(),
                                     ClientUI::MeterIcon(METER_POPULATION),
                                     0,0,3,3,false,false,false,true);
    m_toolbar->AttachChild(m_population);

    m_industry = new StatisticIcon(m_population->UpperLeft().x-LAYOUT_MARGIN-ICON_WIDTH,GG::Y(LAYOUT_MARGIN),ICON_WIDTH,m_turn_update->Height(),
                                   ClientUI::MeterIcon(METER_INDUSTRY),
                                   0,3,false,false);
    m_toolbar->AttachChild(m_industry);

    m_research = new StatisticIcon(m_industry->UpperLeft().x-LAYOUT_MARGIN-ICON_WIDTH,GG::Y(LAYOUT_MARGIN),ICON_WIDTH,m_turn_update->Height(),
                                   ClientUI::MeterIcon(METER_RESEARCH),
                                   0,3,false,false);
    m_toolbar->AttachChild(m_research);

    m_trade = new StatisticIcon(m_research->UpperLeft().x-LAYOUT_MARGIN-ICON_DUAL_WIDTH,GG::Y(LAYOUT_MARGIN),ICON_DUAL_WIDTH,m_turn_update->Height(),
                                ClientUI::MeterIcon(METER_TRADE),
                                0,0,3,3,false,false,false,true);
    m_toolbar->AttachChild(m_trade);

    m_mineral = new StatisticIcon(m_trade->UpperLeft().x-LAYOUT_MARGIN-ICON_DUAL_WIDTH,GG::Y(LAYOUT_MARGIN),ICON_DUAL_WIDTH,m_turn_update->Height(),
                                  ClientUI::MeterIcon(METER_MINING),
                                  0,0,3,3,false,false,false,true);
    m_toolbar->AttachChild(m_mineral);

    m_food = new StatisticIcon(m_mineral->UpperLeft().x-LAYOUT_MARGIN-ICON_DUAL_WIDTH,GG::Y(LAYOUT_MARGIN),ICON_DUAL_WIDTH,m_turn_update->Height(),
                               ClientUI::MeterIcon(METER_FARMING),
                               0,0,3,3,false,false,false,true);
    m_toolbar->AttachChild(m_food);
The second parameter from the back for the Structor of an Icon WITHOUT in-/decreasing rate in brackets,
The third and fourth parameter from the back for the Structor of an Icon WITH in-/decreasing rate in brackets
are the integerize parameters. (i have set all to false here...)

I think this 'integerize' isn't very useful in the way how it works....
A population of 25.0 people is some kind of weird where there are only whole numbers of people...
But when 'integerized' to fix this, a population of 1450 would be formatted to 1k which cuts very much information...

Is this topic worth more investigation? =)
Or are there more severe things to do?

User avatar
Geoff the Medio
Programming, Design, Admin
Posts: 12802
Joined: Wed Oct 08, 2003 1:33 am
Location: Munich

Re: DoubleToString

#29 Post by Geoff the Medio »

Kuhlschrank wrote:So there really is NO need for this integerization?
We're probably fine without it.
Kuhlschrank wrote:I think this 'integerize' isn't very useful in the way how it works.... [...] a population of 1450 would be formatted to 1k which cuts very much information...
This is the bug in how DoubleToString handles the integerize flag. It should round 1435.5 to 1435 (an integer).
A population of 25.0 people is some kind of weird where there are only whole numbers of people...
"Population" isn't individual people. Rather, it's population points, which are a race-neutral measure of population. A single population point can be thought of as roughly 1 billion humans.
Is this topic worth more investigation? =)
Yes. Particularly since there are other issues with DoubleToString than the integerize flag. See the discussions earlier in this thread.
Or are there more severe things to do?
Depends what you mean by severe...

User avatar
Kuhlschrank
Space Floater
Posts: 24
Joined: Fri Mar 27, 2009 11:50 pm

Re: DoubleToString

#30 Post by Kuhlschrank »

Geoff the Medio wrote:This is the bug in how DoubleToString handles the integerize flag. It should round 1435.5 to 1435 (an integer).
So, when integerize is set tot true, the variable digits has no meaning anymore?
Geoff the Medio wrote:"Population" isn't individual people. Rather, it's population points, which are a race-neutral measure of population. A single population point can be thought of as roughly 1 billion humans.
OK
Geoff the Medio wrote:
Is this topic worth more investigation? =)
Yes. Particularly since there are other issues with DoubleToString than the integerize flag. See the discussions earlier in this thread.
I'll take a look at this soon... =)

Post Reply