Re: [Oorexx-devel] Problem? with OORexx API function ObjectToDouble

2021-04-20 Thread Erich Steinböck
>
> it should not be difficult to directly generate a double value


You'd think so, but read these stunning strtod() algorithm descriptions (a
must-read for anyone who likes math).
https://www.exploringbinary.com/how-strtod-works-and-sometimes-doesnt/
https://www.exploringbinary.com/how-glibc-strtod-works/
___
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel


Re: [Oorexx-devel] Problem? with OORexx API function ObjectToDouble

2021-04-20 Thread Ruurd Idenburg

Rick is right I guess, see result from "LC_NUMERIC=C rexx osmmap.rex"

---

ruurd@Paradigit2:~/newrxgtk/GTKv3/test$ LC_NUMERIC=C rexx osmmap.rex
As CSTRINGs - Latitude: 52.289875;Longitude: 4.8448525
As objects - Latitude: 52.289875;Longitude: 4.8448525
As doubles - Latitude: 52.289875; Longitude: 4.844853
ruurd@Paradigit2:~/newrxgtk/GTKv3/test$

--

As an aside for Erich, I started  with the arguments as float and the 
result triggered the trial bypass via CSTRING.


Ruurd

On 4/19/21 11:25 PM, Rick McGuire wrote:



On Mon, Apr 19, 2021 at 5:09 PM Erich Steinböck 
mailto:erich.steinbo...@gmail.com>> wrote:


Hi Ruurd, instead of defining your latitude/longitude arguments as
CSTRING and then manually converting them, you can define your
arguments as (e. g.) float and have Rexx do the conversion for you.

~~~
float lat, // Latitude in decimal degrees
float lon, // Longitude in decimal degrees
~~~

The actual issue may be a bug as ObjectToDouble calls C's strtod()
which seems to adhere to the locale (decimal dot vs decimal comma).
It seems rexx doesn't globally set the "C" locale but runs with
whatever locale it is being started in.


I suspect that is the case. The actual work is done in method 
NumberString::doubleValue(), which uses strtod() to do the conversion. 
Since the numberstring object already has already parsed off the 
matissa, exponent, and sign, it should not be difficult to directly 
generate a double value from that information.


Rick


Does it work as expected if you run your script in either of these
two forms?
LANG=C rexx 
LC_NUMERIC=C rexx 
___
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/oorexx-devel




___
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel
___
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel


Re: [Oorexx-devel] Problem? with OORexx API function ObjectToDouble

2021-04-19 Thread Rick McGuire
On Mon, Apr 19, 2021 at 5:09 PM Erich Steinböck 
wrote:

> Hi Ruurd, instead of defining your latitude/longitude arguments as CSTRING
> and then manually converting them, you can define your arguments as (e. g.)
> float and have Rexx do the conversion for you.
>
> ~~~
> float lat, // Latitude in decimal degrees
> float lon, // Longitude in decimal degrees
> ~~~
>
> The actual issue may be a bug as ObjectToDouble calls C's strtod() which
> seems to adhere to the locale (decimal dot vs decimal comma).
> It seems rexx doesn't globally set the "C" locale but runs with whatever
> locale it is being started in.
>

I suspect that is the case. The actual work is done in method
NumberString::doubleValue(), which uses strtod() to do the conversion.
Since the numberstring object already has already parsed off the matissa,
exponent, and sign, it should not be difficult to directly generate a
double value from that information.

Rick

>
> Does it work as expected if you run your script in either of these two
> forms?
> LANG=C rexx 
> LC_NUMERIC=C rexx 
> ___
> Oorexx-devel mailing list
> Oorexx-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/oorexx-devel
>
___
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel


Re: [Oorexx-devel] Problem? with OORexx API function ObjectToDouble

2021-04-19 Thread Erich Steinböck
Hi Ruurd, instead of defining your latitude/longitude arguments as CSTRING
and then manually converting them, you can define your arguments as (e. g.)
float and have Rexx do the conversion for you.

~~~
float lat, // Latitude in decimal degrees
float lon, // Longitude in decimal degrees
~~~

The actual issue may be a bug as ObjectToDouble calls C's strtod() which
seems to adhere to the locale (decimal dot vs decimal comma).
It seems rexx doesn't globally set the "C" locale but runs with whatever
locale it is being started in.

Does it work as expected if you run your script in either of these two
forms?
LANG=C rexx 
LC_NUMERIC=C rexx 
___
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel


Re: [Oorexx-devel] Problem? with OORexx API function ObjectToDouble

2021-04-19 Thread Ruurd Idenburg
I guess I found the cause. It's the decimal point vs the decimal comma 
(for my locale) that is causing the behaviour.


If I set the latitude and longitude in an ENVIRONMENT variable via VALUE 
and retrieve those with GObject "g_getenv" function, then all goes well 
if I use the comma as decimal point but shows the same problem if I use 
the dot as the decimal point in the string given to VALUE.


___

Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel



___
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel


Re: [Oorexx-devel] Problem? with OORexx API function ObjectToDouble

2021-04-19 Thread Ruurd Idenburg
In the real code the tildes in the printf as objects are "->". Made a 
mistake when I type the code manually.


On 4/19/21 3:50 PM, Ruurd Idenburg wrote:


Given the following code:

/**
 * Method: OsmMapPointNew
 *
 * Create a new OsmMapPoint.
 *
 * @return 0
 **/
RexxMethod3(int,    // Return type
    OsmMapPointNew, // Method name
    CSTRING, lat,   // Latitude in decimal degrees
    CSTRING, lon,   // Longitude in decimal degrees
    OSELF, self)    // Self
{

    printf("As CSTRINGs - Latitude: %s;Longitude: %s\n", lat, lon);

    RexxStringObject rxlat = context->String(lat);
    RexxStringObject rxlon = context->String(lon);

    printf("As objects - Latitude: %s;Longitude: %s\n)", 
context~StringData(rxlat), context~StringData(rxlon));


    double flat; context->ObjectToDouble(rxlat,);
    double flon; context->ObjectToDouble(rxlon,);

    printf"(As doubles - Latitude: %.6f; Longitude: %.6f \n", flat, 
flon);


    OsmGpsMapPoint *point = osm_gps_map_point_new_degrees((float)flat, 
(float)flon);


    context->SetObjectVariable("POINT", context->NewPointer(point));

    return 0;
}

And given the following result when invoked:

ruurd@Paradigit2:~/newrxgtk/GTKv3/test$ osmmap.rex
As CSTRINGs - Latitude: 52.289875;Longitude: 4.8448525
As objects - Latitude: 52.289875;Longitude: 4.8448525
As doubles - Latitude: 52,00; Longitude: 4,00
ruurd@Paradigit2:~/newrxgtk/GTKv3/test$

Is there some misunderstanding on my side or does it look like 
"ObjectToDouble" is in trouble?


Running Mint 20, which is based on Ubuntu 20.4




___
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel



___
Oorexx-devel mailing list
Oorexx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/oorexx-devel