Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 364216 - Both values returned from mathLib.modf are wrong
Summary: Both values returned from mathLib.modf are wrong
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: EDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 372533
  Show dependency tree
 
Reported: 2011-11-19 08:42 EST by broy2 CLA
Modified: 2017-02-23 14:16 EST (History)
6 users (show)

See Also:


Attachments
fix for problem2 (1.03 KB, patch)
2011-12-29 00:50 EST, Huang Ji Yong CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description broy2 CLA 2011-11-19 08:42:28 EST
Use EUnit to run:

library modf
    decimalX decimal(18, 6);
    decimalY decimal(18, 6);
    resultFloat float;
    bigIntY bigInt;
    function modfTest1(){@Test}
        decimalX = 000000771896.039000;
        decimalY = 000000771896.000000;
        bigIntY = decimalY as bigInt;
        resultFloat = mathLib.modf(decimalX, bigIntY);
        LogResult.assertFloatEqual("modf1", 0.03899999998975545, resultFloat);
    end
    function modfTest2(){@Test}
        LogResult.assertBigIntEqual("modf2", 771896, bigIntY);
    end
end

 
modf::modfTest1: FAILED - modf1 - Failed: Expected value = '0.03899999998975545' Actual value = '0.039' 
modf::modfTest2: FAILED - modf2 - Failed: Expected value = '771896' Actual value = '0' 

MathLib.modf splits a numeric value into two components: an integer and a fraction. The integer is returned to the second argument, and the fraction is the return value.
Comment 1 Jing Qian CLA 2011-11-21 20:11:16 EST
deferred
Comment 2 Huang Ji Yong CLA 2011-12-29 00:50:41 EST
Created attachment 208837 [details]
fix for problem2
Comment 3 Huang Ji Yong CLA 2011-12-29 00:55:03 EST
There are 2 problems here
1. modf::modfTest1: FAILED - modf1 - Failed: Expected value =
'0.03899999998975545' Actual value = '0.039' 
2. modf::modfTest2: FAILED - modf2 - Failed: Expected value = '771896' Actual
value = '0'

The fix for problem 2 is committed.

Regarding problem 1, according to the comment in bug 360863, the value should be the default of the platform.
There is no modf function in js, according to the definition of modf, I think the expected value should be '0.039'. Thus we may need to change test case for javascript.

Brian, what do you think?
Comment 4 Matt Heitz CLA 2012-01-13 17:27:32 EST
I also think problem 1 is not a defect.
Comment 5 Huang Ji Yong CLA 2012-01-15 20:34:54 EST
Route to Kathy to change the testcase.
If any problems, reopen it for me, thanks.
Comment 6 Brian Svihovec CLA 2012-01-16 15:31:02 EST
I talked with Tim about this, and we agree that test 1 should print 0.039.
Comment 7 Kathy Carroll CLA 2012-02-24 11:00:21 EST
I've modified the test variations based on comment 6.  Now Java gen 0.8 has new failures that aren't regressions from 0.70.  

Here are the failing variations:

package mini;

// basic library
library modfTester
	
    decimalX decimal(18, 6);
    decimalY decimal(18, 6);
    resultFloat float;
    bigIntY bigInt;
    
    y int; 
    x, result smallFloat;  
    
    aFloat float;
    answer float;
   	ir int;
   	aDecimal decimal(18, 6);

    function modfTest1(){@Test}
        decimalX = 000000771896.039000;
        decimalY = 000000771896.000000;
        bigIntY = decimalY as bigInt;
        resultFloat = mathLib.modf(decimalX, bigIntY);
        logresult.logStdOut(resultFloat);
        LogResult.assertFloatEqual("modf1 BUG 364216 reference comment 6", 0.039, resultFloat);
    end
    
    function modfTest2(){@Test}
        LogResult.assertBigIntEqual("modf2 BUG 364216", 771896, bigIntY);
    end
   
    function modfTest3(){@Test}
        x = 23.5678;
        try
            result = mathLib.modf(x, y);
        onException(oops AnyException)
            LogResult.failed("Exception");
            exit;
        end
        LogResult.assertFloatEqual("modf BUG 36217/364216 reference comment 6", 0.5678, result);
    end

    function modfTest4(){@Test}
        LogResult.assertFloatEqual("modf", 23, y);
    end

    function testModf6(){@Test}
	afloat = 3245.435;
      answer = MathLib.modf(afloat, ir);
     	LogResult.assertBigIntEqual("modf( float, smallint ) #2 integet", 3245, ir);
	LogResult.assertFloatEqual("modf( float, smallint ) #2 fractional", 0.435, answer);
    end

    function testModf7(){@Test}
      afloat = -987654.32109;
      answer = MathLib.modf(afloat, ir);    
      LogResult.assertBigIntEqual("modf( float, smallint ) #3 integet", -987654, ir);
	LogResult.assertFloatEqual("modf( float, smallint ) #3 fractional", -0.32109, answer);        
    end

    function testModf9(){@Test}
      adecimal = 3245.435;
      answer = MathLib.modf(adecimal, ir);
      LogResult.assertBigIntEqual("modf( decimal, smallint ) #2 integet", 3245, ir);
	LogResult.assertFloatEqual("modf( decimal, smallint ) #2 fractional", 0.435, answer);
    end

    function testModf10(){@Test}
      adecimal = -987654.32109;
      answer = MathLib.modf(adecimal, ir);
      LogResult.assertBigIntEqual("modf( decimal, bigint ) #3 integet", -987654, ir);
	LogResult.assertFloatEqual("modf( decimal, bigint ) #3 fractional", -0.32109, answer);  
    end
    
end
Comment 8 Jeff Douglas CLA 2012-02-24 13:34:45 EST
The modf javagen runtime function gives an approximation for the decimals side of things, because the the new Decimal(numericField1) call. We are dealing with floating point values, so it is possible to have approximations made.

We discussed this in the scrum, and we are assigning this to the language defect list, to see what we want to do about it.
Comment 9 Matt Heitz CLA 2012-02-24 13:54:41 EST
Part of the problem may be that the Java and JavaScript code give different results when converting from decimal to float.  

    function modfTest1(){@Test}
        x float = 771896.039e0;   // changed
        decimalY = 000000771896.000000;
        bigIntY = decimalY as bigInt;
        resultFloat = mathLib.modf(x, bigIntY);  // changed
        logresult.logStdOut(resultFloat);
        LogResult.assertFloatEqual("modf1 BUG 364216 reference comment 6",
0.039, resultFloat);
    end


Also, the little C program below says that the correct answer is 0.039.

#include <stdio.h>
#include <math.h>

main()
{
	double blah;
	printf( "%f\n", modf( 771896.039, &blah ) );
}
Comment 10 Matt Heitz CLA 2012-11-18 22:35:00 EST
There's nothing more to do with this.  The code is working correctly.