| Summary: | Both values returned from mathLib.modf are wrong | ||||||
|---|---|---|---|---|---|---|---|
| Product: | z_Archived | Reporter: | broy2 | ||||
| Component: | EDT | Assignee: | Project Inbox <edt.language-inbox> | ||||
| Status: | CLOSED FIXED | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | hjiyong, jeffdouglas, mayunf, mheitz, smythew, svihovec | ||||
| Version: | unspecified | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows XP | ||||||
| Whiteboard: | |||||||
| Bug Depends on: | |||||||
| Bug Blocks: | 372533 | ||||||
| Attachments: |
|
||||||
deferred Created attachment 208837 [details]
fix for problem2
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? I also think problem 1 is not a defect. Route to Kathy to change the testcase. If any problems, reopen it for me, thanks. I talked with Tim about this, and we agree that test 1 should print 0.039. 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 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. 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 ) );
}
There's nothing more to do with this. The code is working correctly. |
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.