Skip to content

Builtin math: ^ operator is left-associative #6280

Closed

Description

@0x005c

The result of math '3^0.5^2' is currently:

~> math '3^0.5^2'
3

That mean, ^ operator is left-associative.
I think this is a bug because exponentiation operators in many languages are right-associative.

version:

~> fish --version
fish, version 3.0.2-1757-g47c0b5f9

Activity

  1. added
    bug
    on Nov 7, 2019
  2. added this to the fish-future milestone on Nov 7, 2019
  3. ridiculousfish commented on Nov 7, 2019

    @ridiculousfish
    Member

    Seems like a fun isolated bug to tackle for anyone interested. Thanks for filing!

  4. ankush-0x90 commented on Nov 8, 2019

    @ankush-0x90
    Contributor

    Hie @ridiculousfish, I am really interested. Issue is really interesting and as I am new here I will need a little help. I have built it and I am looking into tinyexpr.cpp but not sure about changes..

  5. floam commented on Nov 8, 2019

    @floam
    Member

    Easy fix. This is configurable in upstream TinyExpr and that author just likes the left-to-right because that's how spreadsheets do it. I think it will confuse people. Let's change it.

  6. floam commented on Nov 8, 2019

    @floam
    Member

    If you want to give it a shot @asprazz, go ahead! Look at this code upstream:

    https://github.com/codeplea/tinyexpr/blob/ffb0d41b13e5f8d318db95feb071c220c134fe70/tinyexpr.c#L415

    See it has a compile time option for TE_POW_FROM_RIGHT? That provides a different version of the factor() function which has a while loop with different logic. Ours needs to be adapted to do the same thing. We've diverged and minimized our code from theirs a bit so there may be some adaptation required, it may be a fun practice to try to apply/translate the same differences you see to our codebase if you like!

  7. ankush-0x90 commented on Nov 9, 2019

    @ankush-0x90
    Contributor

    @floam Thank you for clarification. I will be working on this now.. :) 💯

  8. ankush-0x90 commented on Nov 9, 2019

    @ankush-0x90
    Contributor

    Hie @floam, Can you please look into my changes ?
    I have removed a bunch of code saying => -a^b = -(a^b) as -2^2 = 4 not -4
    Not sure about this tho :)
    I have found an issue on upstream codeplea/tinyexpr#52

    Hey @floam, Thank you for guiding me out. Btw I have created a PR (may be someone will) please review it whenever possible

  9. ArashPartow commented on Mar 19, 2020

    @ArashPartow

    This issue was raised with the author a long time ago:

    codeplea/tinyexpr#10 (comment)

  10. locked as resolved and limited conversation to collaborators on Jun 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions