Comments (4)
To be honest, I don't see that big of a difference — it merely checks out two use cases (positive and negative) times two sources (constant or value coming from a file).
But, well, [-10; 10]
will work the same too. Feel free to implement ;)
from kaitai_struct.
The question what is expected results for -10...10 / 3
and -10...10 / -3
? Different languages seems to have different opinions and this opinion is not covered by tests. The result can depend on rounding and it is better to explicitly differentiate, we expect to get floor(a / b)
, ceil(a / b)
, or round(a / b)
(assuming here that it is float division) and with what sign.
from kaitai_struct.
Did you not see the comment at the top of the KSY spec
expr_int_div.ksy
that you were pointing to?
Yes, strangely, but it is true. I really didn't notice it.
The investigation in #746, however, somehow ignored the issue with a negative divisor.
Also for me it is strange that as the test use of strange numbers which result of division it is heavy to calculate manually and that only couple of values from all (incomplete) described table are checked was chosen. I'll prepare PR with exhaustive tests soon. I only hope that it will not stuck as other my (and not only my) PRs here.
from kaitai_struct.
The question what is expected results for
-10...10 / 3
and-10...10 / -3
?
Sometimes I can't decode what you mean by your sentences - is that your question? Did you not see the comment at the top of the KSY spec expr_int_div.ksy
that you were pointing to?
# Tests division operation, both positive and negative
# See https://github.com/kaitai-io/kaitai_struct/issues/746
# => the KS division operation `a / b` should do `floor(a / b)`
I think this states the expected behavior clear enough and it even provides a link to #746 with detailed explanation.
The result can depend on rounding
Hypothetically, it probably could if the corresponding translator method of some target in KSC was implemented by someone who doesn't know the correct semantics, but as far as I know, it doesn't in any target language at the moment (i.e. (4 / 3) == (5 / 3)
is true in all languages, even though mathematically 4 / 3 = 1.33
and 5 / 3 = 1.67
, so if the integer division result depended on rounding, they wouldn't be equal - see also the table in #746 (comment) with real results from all target languages).
just test division of everything in range [-10; 10] by 3 and -3
This sounds like the table @dgelessus made (the columns to look at would be floor(i / 3)
and "i % 3
behavior 2"), see the expandable section at the bottom of #746 (comment) that says:
▸ Table to compare division and modulo behaviors
As @GreyCat said, feel free to improve the test as you see fit, at least we'll have something concrete to discuss.
from kaitai_struct.
Related Issues (20)
- `bytes.to_s(encoding)` should validate the passed encoding
- Using enum members as int is broken in ruby HOT 3
- Add explanation to errors `spec_build_failed` and `format_build_failed` on https://ci.kaitai.io/ HOT 1
- C++: the type of all integer constants wrongly deduced as `int32_t` HOT 1
- ci.kaitai.io: use snake_case for test names instead of PascalCase HOT 1
- Java: byte array elements propageted to `int` as signed values (0xFF -> -1 instead of 255)
- Invalid Java code generated: Incompatible types: possible lossy conversion from int to byte HOT 3
- Ruby, Lua: missing `require`s not detected by tests due to `require` leaks HOT 1
- Invalid Java code generated: Switch selectors cannot be of type "long" HOT 1
- Recursive decoding of value HOT 3
- Python: Fix missing `assertRaisesRegexp` method in Python 3.12
- C++11: segfault in debug mode for arrays HOT 1
- Construct: the order of `Computed` fields matter
- How to disable building documentation and JS?
- Health of the project?
- Support for Julia HOT 1
- Error: Could not find or load main class io.kaitai.struct.JavaMain HOT 5
- Extended nullabillity support for Kotlin and other null-safe languages
- C# Serialization HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kaitai_struct.