Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decimal_type_test.go: Floating points failed on aarch64-darwin #766

Open
htran-opencolo opened this issue Jan 31, 2023 · 8 comments
Open

Comments

@htran-opencolo
Copy link

How fatal are these errors to ygot subcomponents?

last 10 log lines:
       >         decimal_type_test.go:278: ranges [-inf,-], [0,+]: -5.05 should be outside ranges -0.0|0.0..10.1
       >         decimal_type_test.go:278: ranges [-inf,-], [0,+]: -0.001 should be outside ranges -0.0|0.0..10.1
       >     --- FAIL: TestValidateDecimalValue/ranges_[-,-],_[0,+inf] (0.00s)
       >         decimal_type_test.go:278: ranges [-,-], [0,+inf]: -10.15 should be outside ranges -0.0|0.0..922337203685477580.8
       >         decimal_type_test.go:278: ranges [-,-], [0,+inf]: -5.0009 should be outside ranges -0.0|0.0..922337203685477580.8
       >         decimal_type_test.go:278: ranges [-,-], [0,+inf]: -0.0001 should be outside ranges -0.0|0.0..922337203685477580.8
       > E0131 16:36:09.564155   13273 util_types.go:383] unexpected type bits in yangBuiltinTypeToGoPtrType
       > FAIL
       > FAIL        github.com/openconfig/ygot/ytypes       0.358s
       > FAIL

Screenshot 2023-01-31 at 9 37 23 AM

@wenovus
Copy link
Collaborator

wenovus commented Feb 1, 2023

Interesting, we haven't tested ygot on ARM machines. Go is supposed to have good support for ARM so I'm not sure what's happening here. I would be willing to review an update to our GitHub actions workflow that adds validation on the ARM architecture.

@htran-opencolo
Copy link
Author

Do you have some pointers on running GH Actions on ARM architecture? Came across a discussion using QEMU with cross-compilation here https://github.com/orgs/community/discussions/25319

I would be interested in learning more about Go ecosystem, specifically with cross-compiling.

@wenovus
Copy link
Collaborator

wenovus commented Feb 2, 2023

I see an action that some people are using, I think it might be the same QEMU emulation you're talking about:

@robshakir
Copy link
Contributor

robshakir commented Feb 2, 2023

I think this is darwin, right? I wonder whether we can use the macos-latest target to run on M1? docs.

w.r.t the initial question -- these failures will mean that decimal64 values that have ranges specified on them that use the infinity value are very likely to produce erroneous validation results. It looks like generally, the decimal64 ranges WAI, but the inf keyword is an issue.

@robshakir
Copy link
Contributor

Oh, aologies -- these are not actually available it looks like. Sorry for the noise.

@dbourkey
Copy link

dbourkey commented Mar 4, 2023

According to the YANG 6020 Spec decimal64 values are defined as fixed point decimal numbers.

The "fraction-digits" statement, which is a substatement to the
"type" statement, MUST be present if the type is "decimal64". It
takes as an argument an integer between 1 and 18, inclusively. It
controls the size of the minimum difference between values of a
decimal64 type, by restricting the value space to numbers that are
expressible as "i x 10^-n" where n is the fraction-digits argument.

I understand the obvious value of storing values as native Go types. However, perhaps in light of this issue, and the problems of lost resolution in floating point numbers, it would be best to model decimal64 as a fixed point number, and do all validation with fixed point number operations.

I have observed issues in existing Yang models with values being incorrectly rejected due to floating-point conversions pushing the value outside of the defined ranges for the leaf. Users may expect a level of precision that floating point numbers cannot provide.

OpenConfig/goyang defines the yang.Number type in openconfig/goyang/pkg/yang/types_builtin.go. I would propose that this type should be used instead of float64s. This would fix the issues of decimal64 tests failing on M1, and generally make the code more portable.

I would like to work on this. Are there any other considerations I should be aware of before I spend time implementing such a change and opening a PR?

@robshakir
Copy link
Contributor

In practice, we have found that fixed-precision numbers are generally not what is required for the data that we are actually modelling. This approach (use of float64) seems more coherent with the actual usage [0].

The change you propose will be majorly backwards incompatible for users, such that if it is pursued, it needs to be done behind a specific flag that cannot be the default to accommodate existing users of ygot for whom this functionality has not been a problem.

[0]: in OpenConfig models, we defined an ieeefloat32 type that has generally been used since its inception for all non-integer numbers.

@dbourkey
Copy link

dbourkey commented Mar 9, 2023

I understand, thank you for sharing that context. It sounds like implementing a flag for using a fixed-point model might not be worth the extra code-complexity & maintenance it brings. I will work on this for my own purposes, and will open a PR only if there is a nice clean way to do it without impacting the codebase too much.

Edit: Apologies for going off-topic, this implementation would not fix the original issue discussed here.

robshakir added a commit to openconfig/goyang that referenced this issue Jul 10, 2024
 * (M) pkg/yang/types_builtin(_test)?.go
    - This change squashes a bug that has existed for a long time
      in `FromFloat`, but only shows up on arm64. I finally have an
      arm64 machine and so found the issue. It was originally reported
      in openconfig/ygot#766. The issue is
      that uint64 of a negative float64 is undefined  -- and on arm64
      on darwin returns 0, which made some test cases fail only on this
      architecture.
robshakir added a commit to openconfig/goyang that referenced this issue Jul 10, 2024
* Fix an age-old bug with `FromFloat` handling of negatives.

 * (M) pkg/yang/types_builtin(_test)?.go
    - This change squashes a bug that has existed for a long time
      in `FromFloat`, but only shows up on arm64. I finally have an
      arm64 machine and so found the issue. It was originally reported
      in openconfig/ygot#766. The issue is
      that uint64 of a negative float64 is undefined  -- and on arm64
      on darwin returns 0, which made some test cases fail only on this
      architecture.

* Add missing comment.

* `gofmt`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants