A third alternative could be to round the result and compare against the 
rounded value. Epsilon is probably the better idea. I think different infosets 
per JVM would be too brittle and difficult to keep up-to-date. 

// Mike

-----Original Message-----
From: Mike Beckerle <mbecke...@apache.org> 
Sent: Sunday, September 24, 2023 12:09
To: dev@daffodil.apache.org
Subject: Comparing Floating Point numbers

So Java 21 produces different floating point values in a few cases. Some of our 
tests (4) are sensitive to this.

The "right way" to compare floating point numbers is like this:

If(Math.abs(A - B) < epsilon)

The TDML runner has outstanding bug
https://issues.apache.org/jira/browse/DAFFODIL-2402 which is to add the ability 
to put xsi:type="double" for example on the expected infoset, and this 
instructructs the (schema unaware) TDML runner to do comparison using some sort 
of epsilon comparison like the above

Does that seem like the right fix for this?

The only alternative I can think of is some sort of conditional infoset 
construction, so that the expected values can vary for different JVMs.

On Sat, Sep 23, 2023 at 2:13 PM Mike Beckerle <mbecke...@apache.org> wrote:

>
> JVM 21 LTS is now out.
>
> So I decided to try to building Daffodil using it. My WIP PR is
> https://github.com/apache/daffodil/pull/1090
>
> It looks pretty close.
>
> The --release 8 option for javac is now deprecated. So I 
> conditionalized that.
> Fixed some deprecated calls.
>
> Remaining issues:
>
> 2 more deprecated calls (hence fatal warnings turned off for now)
>
> 5 tests fail. One each in these 3 test classes
>
> org.apache.daffodil.TresysTests.test_BG000
>
> org.apache.daffodil.section13.text_number_props.TestTextNumberProps.te
> st_textNumberPattern_exponent01
>
>
> org.apache.daffodil.section05.simple_types.TestSimpleTypes.test_double
> _binary_06
>
> All 3 of those failures are floating point related like this: 
> (highlighted digit isn't output any more)
>
> [error] Expected (attributes stripped)
> [error]    <d_02>9.8765432109876544E16</d_02>
> [error] Actual (attributes ignored for diff) [error] 
> <ex:d_02>9.876543210987654E16</ex:d_02>
>
> The Expected has one more digit 4 at the end.
>
> 1 other test failure is for reasons unknown. Possible change in regex 
> behavior?
>
>
> org.apache.daffodil.io.layers.TestJavaIOStreams.testBase64ScanningForD
> elimiter1
>
> One CLI test failure:
>
>
> org.apache.daffodil.cli.cliTest.TestEXIEncodeDecode.test_CLI_Encode_De
> code_EXI
>
>
>

Reply via email to