[Scummvm-devel] sscanf/%f (was: setlocale() doesn't work at Symbian)

Willem Jan Palenstijn wjp at usecode.org
Thu Feb 19 12:38:41 CET 2015


On Thu, Feb 19, 2015 at 01:14:59PM +0200, Filippos Karapetis wrote:
> Well, it looks like sscanf() on Symbian isn't handling floating-point math
> correctly (same as most floating point calculations in Symbian).
> 
> This StackOverflow question seems to verify this similar behavior with
> atof() under Symbian:
> http://stackoverflow.com/questions/11895686/atof-is-not-taking-entire-value-in-symbian
> 
> If that is indeed the case, the only way to make this work is to roll our
> own version of sscanf(), and handle floating-point math for Symbian in
> there.



Or just avoid the use of %f in sscanf in our engines.


-Willem Jan



> On Wed, Feb 18, 2015 at 8:43 PM, Федор <fedor_qd at mail.ru> wrote:
> 
> > Result is same.
> >
> >
> > Fedor Strizhnev
> > Федор Стрижнёв.
> >
> > Серада, 18 лютага 2015, 20:35 +02:00 ад Filippos Karapetis <
> > bluegr at gmail.com>:
> >
> >   You're getting wrong results for sscanf(), which is why ZVision isn't
> > working for you
> >
> > Try putting this line:
> > setlocale(LC_ALL, "C");
> > before your test code and try again
> >
> > On Wed, Feb 18, 2015 at 8:23 PM, Федор <fedor_qd at mail.ru
> > <https://e.mail.ru/compose/?mailto=mailto%3afedor_qd@mail.ru>> wrote:
> >
> > I have:
> > Test dot: 30.000000
> > Test comma: 30.000000
> >
> > I confused.
> >
> > Fedor Strizhnev
> > Федор Стрижнёв.
> >
> > Серада, 18 лютага 2015, 14:44 UTC ад Willem Jan Palenstijn <
> > wjp at usecode.org
> > <https://e.mail.ru/compose/?mailto=mailto%3awjp@usecode.org>>:
> >
> >   On Wed, Feb 18, 2015 at 02:42:08PM +0300, Fiodar Strizhniou wrote:
> > > Is this test code good?
> > >
> > >
> > > sscanf("30.981", "%f", &y)
> > > printf("Test dot: \n")
> > > print y;
> > > sscanf("30,981", "%f", &y)
> > > printf("Test comma: \n")
> > > print y;
> >
> >
> > I had a quick look at how ZVision uses sscanf, and something like that
> > sounds
> > good, yes.
> >
> > If you want something that actually compiles, try:
> >
> >         float y;
> >         sscanf("30.981", "%f", &y);
> >         printf("Test dot: %f\n", y);
> >         sscanf("30,981", "%f", &y);
> >         printf("Test comma: %f\n", y);
> >
> >
> > You should get as output:
> >
> > Test dot: 30.981001
> > Test comma: 30.000000
> >
> >
> > -Willem Jan
> >
> >
> > > исходное сбщ
> > > Тема: Re: [Scummvm-devel] setlocale() doesn't work at Symbian
> > > От: Федор <fedor_qd at mail.ru
> > <https://e.mail.ru/compose?To=fedor_qd@mail.ru>>
> > > Дата: 17.02.2015 17.44
> > >
> > > I don't know what I need to test. Can you give me peace of code?
> > >
> > >
> > > Fedor Strizhnev
> > > Федор Стрижнёв.
> > >
> > > Аўторак, 17 лютага 2015, 13:47 UTC ад Willem Jan Palenstijn <
> > wjp at usecode.org <https://e.mail.ru/compose?To=wjp@usecode.org>>:
> > > >On Tue, Feb 17, 2015 at 04:06:00PM +0300, Fiodar Strizhniou wrote:
> > > >> I create bugreport month ago about bad colours in most scenes in
> > Zvision engine games. I get point to wrong setlocale() settings in some
> > backends. I create and run test app. Nothing works(see screenshot). Also i
> > have read somewhere in Symbian Sdk docs what setlocale doesnt work at
> > Symbian.
> > > >
> > > >
> > > >You should really say things like that directly, instead of having us
> > guess at
> > > >what you're trying to do.
> > > >
> > > >
> > > >The main question is: does sscanf work with "%f" for you? And if you
> > set locale
> > > >to "C" explicitly?
> > > >
> > > >
> > > >-Willem Jan
> > > >
> > > >
> > > >
> > > >> исходное сбщ
> > > >> Тема: Re: [Scummvm-devel] setlocale() doesn't work at Symbian
> > > >> От: Filippos Karapetis < bluegr at gmail.com
> > <https://e.mail.ru/compose?To=bluegr@gmail.com> >
> > > >> Дата: 17.02.2015 14.52
> > > >>
> > > >> You don't use a correct value for the locale
> > > >>
> > > >> You would want something like:
> > > >> setlocale(LC_ALL,"en_GB.ISO-8859-1");
> > > >>
> > > >> Having said that, check backends/platform/sdl/sdl.cpp, where it does
> > this:
> > > >> const Common::String locale = setlocale(LC_ALL, "");
> > > >>
> > > >> // Restore default C locale to prevent issues with
> > > >> // portability of sscanf(), atof(), etc.
> > > >> // See bug #3615148
> > > >> setlocale(LC_ALL, "C");
> > > >>
> > > >> Be careful when changing the locale, you need to reset it afterwards
> > (as
> > > >> the comment mentions).
> > > >>
> > > >> This stackoverflow question may be helpful:
> > > >>
> > http://stackoverflow.com/questions/3191664/list-of-all-locales-and-their-short-codes
> > > >>
> > > >> On Tue, Feb 17, 2015 at 1:08 PM, Fiodar Strizhniou < fedor_qd at mail.ru
> > <https://e.mail.ru/compose?To=fedor_qd@mail.ru> > wrote:
> > > >>
> > > >> > I write simple application and run on phone:
> > > >> > printf("Locale is: %s\n", setlocale(LC_ALL, "en_GB"));
> > > >> > Locale is NULL
> > > >> > Which parts (decimal separators, etc) should be set? Which values
> > from
> > > >> > setlocale() used?
> > > >> > Always yours, Strizhniou Fedor.
> > > >> > С уважением, Стрижнёв Фёдор.
> > > >> >
> > > >>
> > > >>
> > > >> --
> > > >> "Experience is the name every one gives to their mistakes" - Oscar
> > Wilde
> > > >
> > >
> > >
> > >
> > ------------------------------------------------------------------------------
> > > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> > > from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> > > with Interactivity, Sharing, Native Excel Exports, App Integration & more
> > > Get technology previously reserved for billion-dollar corporations, FREE
> > >
> > http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
> > > _______________________________________________
> > > Scummvm-devel mailing list
> > > Scummvm-devel at lists.sourceforge.net
> > <https://e.mail.ru/compose?To=Scummvm%2ddevel@lists.sourceforge.net>
> > > https://lists.sourceforge.net/lists/listinfo/scummvm-devel
> >
> >
> > ------------------------------------------------------------------------------
> > Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> > from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> > with Interactivity, Sharing, Native Excel Exports, App Integration & more
> > Get technology previously reserved for billion-dollar corporations, FREE
> >
> > http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk
> > _______________________________________________
> > Scummvm-devel mailing list
> > Scummvm-devel at lists.sourceforge.net
> > <https://e.mail.ru/compose?To=Scummvm%2ddevel@lists.sourceforge.net>
> > https://lists.sourceforge.net/lists/listinfo/scummvm-devel
> >
> >
> >
> >
> >
> > --
> > "Experience is the name every one gives to their mistakes" - Oscar Wilde
> >
> >
> >
> 
> 
> -- 
> "Experience is the name every one gives to their mistakes" - Oscar Wilde

> ------------------------------------------------------------------------------
> Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
> from Actuate! Instantly Supercharge Your Business Reports and Dashboards
> with Interactivity, Sharing, Native Excel Exports, App Integration & more
> Get technology previously reserved for billion-dollar corporations, FREE
> http://pubads.g.doubleclick.net/gampad/clk?id=190641631&iu=/4140/ostg.clktrk

> _______________________________________________
> Scummvm-devel mailing list
> Scummvm-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/scummvm-devel





More information about the Scummvm-devel mailing list