Giter Site home page Giter Site logo

Comments (4)

GreyCat avatar GreyCat commented on June 16, 2024 1

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.

Mingun avatar Mingun commented on June 16, 2024 1

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.

Mingun avatar Mingun commented on June 16, 2024 1

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.

generalmimon avatar generalmimon commented on June 16, 2024

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?

expr_int_div.ksy:1-3

# 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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.