ecologylab / simplJava

S.IM.PL Project containing implementations for sun java / android java and requisite tests.
2 stars 4 forks source link

Double "rationalToDouble" and silly format discrepancy. #61

Open ghost opened 11 years ago

ghost commented 11 years ago

So, there's this pleasant little piece of code here, in DoubleType.java that theoretically lets us parse floaty doubles (1/2, 1.44423/2344.234234, 1.4e10/2.5e120, etc):

public static double rationalToDouble(String rationalString)
    {
        String[] stringD    = rationalString.split("/", 2);
        double d0               = Double.parseDouble(stringD[0]);
        double d1                   = Double.parseDouble(stringD[1]);

        return d0 / d1;
    }

This gets called by getInstance() if the string is a floaty fraction string:


@Override
    public Double getInstance(String value, String[] formatStrings,
            ScalarUnmarshallingContext scalarUnmarshallingContext)
    {
        return "null".equalsIgnoreCase(value) ? null : (value != null && value.contains("/")) ?  rationalToDouble(value) : new Double(value);
    }

but doesn't get called by getValue(...)

/**
 * Convert the parameter to double.
 */
public double getValue(String valueString)
{
    return Double.parseDouble(valueString);
}

Which means that it doesn't get called by setValue(...) when we do deserialization:

    /**
     * This is a primitive type, so we set it specially.
     * 
     * @see simpl.types.ScalarType#setField(Object, Field, String)
     */
    @Override
    public boolean setField(Object object, Field field, String value)
    {
        boolean result = false;
        try
        {
            field.setDouble(object, getValue(value));
            result = true;
        }
        catch (Exception e)
        {
            setFieldError(field, value, e);
        }
        return result;
    }

So, the current status quo in our code is to use a semi-sane double format, rather than a weird fractiony format. Should the new scalar types keep the fractiony format, or should we just have a standard double format?

I"m voting that we pick a double format that makes sense / is relatively standard / can be parsed by anyone... the fraction format as is doesn't seem to support that goal.

@andruidk @amwebb @bilhamil @quyin @rhema

andru1d commented 11 years ago

Sounds like a bug. Are u saying current/past doubles are getting serialized wrong? How will we deal w them?

On Sunday, February 10, 2013, Tom White wrote:

So, there's this pleasant little piece of code here, in DoubleType.java that theoretically lets us parse floaty doubles (1/2, 1.44423/2344.234234, 1.4e10/2.5e120, etc):

public static double rationalToDouble(String rationalString) { String[] stringD = rationalString.split("/", 2); double d0 = Double.parseDouble(stringD[0]); double d1 = Double.parseDouble(stringD[1]);

    return d0 / d1;
}

This gets called by getInstance() if the string is a floaty fraction string:

@Override public Double getInstance(String value, String[] formatStrings, ScalarUnmarshallingContext scalarUnmarshallingContext) { return "null".equalsIgnoreCase(value) ? null : (value != null && value.contains("/")) ? rationalToDouble(value) : new Double(value); }

but doesn't get called by getValue(...)

/* * Convert the parameter to double. /public double getValue(String valueString){ return Double.parseDouble(valueString);}

Which means that it doesn't get called by setValue(...) when we do deserialization:

/**     * This is a primitive type, so we set it specially.     *      * @see simpl.types.ScalarType#setField(Object, Field, String)     */
@Override
public boolean setField(Object object, Field field, String value)
{
    boolean result = false;
    try
    {
        field.setDouble(object, getValue(value));
        result = true;
    }
    catch (Exception e)
    {
        setFieldError(field, value, e);
    }
    return result;
}

So, the current status quo in our code is to use a semi-sane double format, rather than a weird fractiony format. Should the new scalar types keep the fractiony format, or should we just have a standard double format?

I"m voting that we pick a double format that makes sense / is relatively standard / can be parsed by anyone... the fraction format as is doesn't seem to support that goal.

@andruidk https://github.com/andruidk @amwebbhttps://github.com/amwebb @bilhamil https://github.com/bilhamil @quyin https://github.com/quyin @rhema https://github.com/rhema

— Reply to this email directly or view it on GitHubhttps://github.com/ecologylab/simplJava/issues/61..

andruid kerne, ph.d. director, interface ecology lab associate professor, department of computer science and engineering texas a&m university 979.862.3684 fax college station, tx 77843-3112 http://ecologylab.net

http://facebook.com/ecologylab

Interfaces are the multidimensional border zones through which the interdependent relationships of people, activities, codes, components, and systems are constituted. Interface ecology investigates the dynamic interactions of media, cultures, and disciplines that flow through interfaces.

ghost commented 11 years ago

Not nescessarily.... I'd have to try and go back to past code to see if the rationalToDouble had been used in the serialization process in the past to know for sure if there's a bug here.

My general feeling is that this probably didn't get used for de/serialization, at leats with the newest code, and so the problem isn't so much that there's a bug but that this functionality was laying around and could possibly have been the intent of Nabeel to keep around.

I don't think it's worth keeping around; so I'm sticking with the vaguely questionable standard pattern of leveraging the java parseDouble functionality instead of using this.

ghost commented 11 years ago

I just wanted to be 100% sure.

bilhamil commented 11 years ago

I may be mistaken, by I believe the whole nasty rational thing came about with exif. I don't have any idea about this code anymore. Although exif uses a binary rational which is basically two integers numerator and denominator.

Bill Hamilton

Interface Ecology Lab | Computer Science and Engineering Department Texas A&M University College Station, Texas, USA

aim/g-talk/email: luin.uial@gmail.com

On Sat, Feb 9, 2013 at 11:31 PM, Tom White notifications@github.com wrote:

I just wanted to be 100% sure.

— Reply to this email directly or view it on GitHubhttps://github.com/ecologylab/simplJava/issues/61#issuecomment-13344737..

andru1d commented 11 years ago

Ah! Exif is a strong motivation to keep that as a deserialization capability.

Toups?

On Sunday, February 10, 2013, Bill Hamilton wrote:

I may be mistaken, by I believe the whole nasty rational thing came about with exif. I don't have any idea about this code anymore. Although exif uses a binary rational which is basically two integers numerator and denominator.

Bill Hamilton

Interface Ecology Lab | Computer Science and Engineering Department Texas A&M University College Station, Texas, USA

aim/g-talk/email: luin.uial@gmail.com <javascript:_e({}, 'cvml', 'luin.uial@gmail.com');>

On Sat, Feb 9, 2013 at 11:31 PM, Tom White <notifications@github.com<javascript:_e({}, 'cvml', 'notifications@github.com');>> wrote:

I just wanted to be 100% sure.

— Reply to this email directly or view it on GitHub< https://github.com/ecologylab/simplJava/issues/61#issuecomment-13344737>..

— Reply to this email directly or view it on GitHubhttps://github.com/ecologylab/simplJava/issues/61#issuecomment-13346398..

andruid kerne, ph.d. director, interface ecology lab associate professor, department of computer science and engineering texas a&m university 979.862.3684 fax college station, tx 77843-3112 http://ecologylab.net

http://facebook.com/ecologylab

Interfaces are the multidimensional border zones through which the interdependent relationships of people, activities, codes, components, and systems are constituted. Interface ecology investigates the dynamic interactions of media, cultures, and disciplines that flow through interfaces.

andru1d commented 11 years ago

I don't have any need to write EXIF, but read, yes. It's probably something many folks in the lab want... -Z


Zachary O. Dugas Toups, Ph.D. TEES Assistant Research Engineer, Games and Interaction TEES Assistant Research Professor, Computer Science & Engineering

Texas Center for Applied Technology Texas A&M University System College Station, Texas, USA

http://ecologylab.net/people/zach

email: toupsz@tamu.edu y! / aim / g-chat / twitter: toupsz

On Sun, Feb 10, 2013 at 5:11 AM, Andruid Kerne andruid@ecologylab.netwrote:

Ah! Exif is a strong motivation to keep that as a deserialization capability.

Toups?

On Sunday, February 10, 2013, Bill Hamilton wrote:

I may be mistaken, by I believe the whole nasty rational thing came about with exif. I don't have any idea about this code anymore. Although exif uses a binary rational which is basically two integers numerator and denominator.

Bill Hamilton

Interface Ecology Lab | Computer Science and Engineering Department Texas A&M University College Station, Texas, USA

aim/g-talk/email: luin.uial@gmail.com

On Sat, Feb 9, 2013 at 11:31 PM, Tom White notifications@github.com wrote:

I just wanted to be 100% sure.

— Reply to this email directly or view it on GitHub< https://github.com/ecologylab/simplJava/issues/61#issuecomment-13344737>..

— Reply to this email directly or view it on GitHubhttps://github.com/ecologylab/simplJava/issues/61#issuecomment-13346398..

andruid kerne, ph.d. director, interface ecology lab associate professor, department of computer science and engineering texas a&m university 979.862.3684 fax college station, tx 77843-3112 http://ecologylab.net

http://facebook.com/ecologylab

Interfaces are the multidimensional border zones through which the interdependent relationships of people, activities, codes, components, and systems are constituted. Interface ecology investigates the dynamic interactions of media, cultures, and disciplines that flow through interfaces.

andru1d commented 11 years ago

It seems clear that the support for Rational deserialization (not serialization!) for Simp Doubles is intentional, and highly beneficial. It is used to read GPS location data from the EXIF headers of images, and perhaps in other GPS use cases.

It does need to be documented better. It also needs use cases to ensure that it gets ported properly.

ghost commented 11 years ago

Does anyone have serialized exif representations they could send me for test cases then?

Sent from my Windows Phone


From: Andruid Kernemailto:notifications@github.com Sent: ‎2/‎10/‎2013 7:34 AM To: ecologylab/simplJavamailto:simplJava@noreply.github.com Cc: Tom Whitemailto:Tom.White@outlook.com Subject: Re: [simplJava] Double "rationalToDouble" and silly format discrepancy. (#61)

I don't have any need to write EXIF, but read, yes. It's probably something many folks in the lab want... -Z


Zachary O. Dugas Toups, Ph.D. TEES Assistant Research Engineer, Games and Interaction TEES Assistant Research Professor, Computer Science & Engineering

Texas Center for Applied Technology Texas A&M University System College Station, Texas, USA

http://ecologylab.net/people/zach

email: toupsz@tamu.edu y! / aim / g-chat / twitter: toupsz

On Sun, Feb 10, 2013 at 5:11 AM, Andruid Kerne andruid@ecologylab.netwrote:

Ah! Exif is a strong motivation to keep that as a deserialization capability.

Toups?

On Sunday, February 10, 2013, Bill Hamilton wrote:

I may be mistaken, by I believe the whole nasty rational thing came about with exif. I don't have any idea about this code anymore. Although exif uses a binary rational which is basically two integers numerator and denominator.

Bill Hamilton

Interface Ecology Lab | Computer Science and Engineering Department Texas A&M University College Station, Texas, USA

aim/g-talk/email: luin.uial@gmail.com

On Sat, Feb 9, 2013 at 11:31 PM, Tom White notifications@github.com wrote:

I just wanted to be 100% sure.

— Reply to this email directly or view it on GitHub< https://github.com/ecologylab/simplJava/issues/61#issuecomment-13344737>..

— Reply to this email directly or view it on GitHubhttps://github.com/ecologylab/simplJava/issues/61#issuecomment-13346398..

andruid kerne, ph.d. director, interface ecology lab associate professor, department of computer science and engineering texas a&m university 979.862.3684 fax college station, tx 77843-3112 http://ecologylab.net

http://facebook.com/ecologylab

Interfaces are the multidimensional border zones through which the interdependent relationships of people, activities, codes, components, and systems are constituted. Interface ecology investigates the dynamic interactions of media, cultures, and disciplines that flow through interfaces.


Reply to this email directly or view it on GitHub: https://github.com/ecologylab/simplJava/issues/61#issuecomment-13349862