Code Monkey home page Code Monkey logo

Comments (4)

nicklockwood avatar nicklockwood commented on July 30, 2024 2

@ingleanthony I didn't want to make this part of the standard feature set originally because ^ is used in some languages to mean bitwise XOR. Expression is extensible though, so you can add your own operators:

let expression = Expression("2 ^ 3", symbols: [
    .infix("^"): { params in pow(params[0], params[1]) },
])

let result = try expression.evaluate() // 8

from expression.

antingle avatar antingle commented on July 30, 2024

I see, that makes sense. Thank you for sharing how to extend Expression with this. I figured there was a way to do it, but could not figure it out right away. Thank you for a great framework!

from expression.

FliiFe avatar FliiFe commented on July 30, 2024

This implementation does not work, as the infix operator does not take precedence over addition. This makes for bizarre maths like : 1-2^6 = 1.
Is there an option to impose precedence ?

from expression.

nicklockwood avatar nicklockwood commented on July 30, 2024

Ah, I see. No, the precedence is hard-coded I'm afraid.

from expression.

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.