Comments (4)
At the moment no. I would like to point out that adding custom functions if quite easy. It's just a matter of extending the Math2 object in the core and then creating a link in the Parser object. For example let's say we wanted to add bitwise and operator functionality and we'll call the function "bitand"
//extend the Math2 object
Math2 = {
...
bitand: function(a, b) {
return a & b;
}
}
//create a link in the Parser object. This accepts an array containing the mapped function
//and the number of arguments it expects. Leave the first blank to use the default name
function Parser() {
...
functions = this.function = {
...
bitand: [ , 2] //2 because it expects 2 arguments
}
}
//then just call it
nerdamer('bitand(5, 7)');
Would this solution suffice?
from nerdamer.
I guess I'm looking for the ability to do x & y and x<<7 without having to
make them functions :-)
On Aug 7, 2016 3:05 PM, "Martin Donk" [email protected] wrote:
At the moment no. I would like to point out that adding custom functions
if quite easy. It's just a matter of extending the Math2 object in the core
and then creating a link in the Parser object. For example let's say we
wanted to add bitwise and operator functionality and we'll call the
function "bitand"//extend the Math2 object
Math2 = {
...
bitand: function(a, b) {
return a & b;
}
}
//create a link in the Parser object. This accepts an array containing the mapped function //and the number of arguments it expects. Leave the first blank to use the default namefunction Parser() {
...
functions = this.function = {
...
bitand: [ , 2] //2 because it expects 2 arguments
}
}
//then just call itnerdamer('bitand(5.7)');Would this solution suffice?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#45 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAs6k9HELCAcC9oeQ2p0aVVa_aIpe3Ojks5qdWeugaJpZM4JebJM
.
from nerdamer.
This would require a little more effort since this would be a modification to the parser itself. I'm hoping to add the ability to add custom operators in future versions but that functionality isn't there at the moment.
from nerdamer.
I think this might actually solve your issue. A few minor modifications allows for support for additional operators. In your case this might help. Note that your compound operator limit is two characters. Anything above will have to be a function. Also it's up to you to define the handling of symbolic types.
This goes after loading nerdamer.
var core = nerdamer.getCore();
var _ = core.PARSER;
//see core source code for full explanation or parameters. In this case just know
//The first param is the operator character so the parser can recognize it
//The second is the name of the parser function that it maps to
//The third is the order
//The third is if it's left associative. And the last is if it's a prefix operator
var Operator = core.Operator;
//create a blank operator so the operator knows it's an operator
//because the parser only sees one character at a time
_.operators['<'] = new Operator('<');
//create the operator you want and we'll name it bitleft. It's up to you. Just make
//sure you call it the same as the function defined below
_.operators['<<'] = new Operator('<<', 'bitleft', 1, true, false);
//define the function
_.bitleft = function(a, b) {
if(!a.isConstant() || !b.isConstant()) {
//do something with symbolic types
}
return a << b;
};
from nerdamer.
Related Issues (20)
- Limit of ((x^2)/(x+1))-((x^2+2)/(x+3)) in inifinity returns -infinity instead of 2
- How to clear defined functions ? HOT 2
- Add Types for nerdamer/all Algebra Extra Solve and Calculus HOT 2
- Error while parsing latex HOT 2
- Function returned from `buildFunction` returns `null` HOT 4
- dot() and cross() don't work with unknowns as parameters HOT 1
- vector addition with an unknown variable HOT 5
- Reference error in SolveFor
- Simplify
- Simplify Error HOT 1
- HUGE error on solveFor HOT 1
- Errors with solveEquations
- Override Physical Constants
- nerdamer.diff("x * sqrt(y)","x") function returning incorrect expression during partial differentiation if the constant term in the equation (in this case sqrt(y)) is under square root HOT 1
- nerdamer.variables error
- SolveEquations not solving correctly
- Invalid latex generated for natural log
- solveEquations not working with too complex equation
- integration result incorrect HOT 1
- Error in basic algebra result
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 nerdamer.