Code Monkey home page Code Monkey logo

formula.js's People

Contributors

0x333333 avatar amilajack avatar danielchatfield avatar ghalimi avatar greyarch avatar grin0c avatar hmalphettes avatar jalateras avatar joaojeronimo avatar kikuchiyo avatar miguelvps avatar nicolashefti avatar patriciali avatar petermoresi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

formula.js's Issues

YEARFRAC and IE8

the formula works fine in ie9 but i cannot get it to work in ie8 gets
'Object doesn't support property or method 'indexOf'' now it says the error is in the jquery included file, but i am sure it has to do with something in forumula.js.

link for reference: http://go.segalco.com/xylem/calc/index.html
thanks,

Dependencies in package.json and bower.json

Hi

I think that in bower.json file 'rm-jstat' package should be replaced with 'jstat' library.

Could you also check number of version and dependencies packages in files package.json and bower.json ?

AVERAGEIF / SUMIF only works for a couple cases

I noticed the following issues with AVERAGEIF and SUMIF not behaving like the implementation in Excel:

  1. AVERAGEIF / SUMIF assumes the cells are numeric for both the range and criteria. It will not successfully compare to text cells.
  2. The criteria parameter requires an operator... there is no implied equals.

Given this example spreadsheet...

A B
1 1 1
2 -1 2
3 yes 3
4 no 4

...here's the result of some formulas we could write:

Formula Works? Issue
=AVERAGEIF(A1:A2, '>0') none
=AVERAGEIF(A1:A2, '1') No implied equals
=AVERAGEIF(A3:A4, 'yes') Fails with text inputs

A few notes:

  • These issues occur whether or not the third optional parameter is used.
  • There are a few more minor differences, but I wouldn't consider them as high of a priority, since they are less commonly used. They include:
    • this implementation doesn't handle wildcards
    • this implementation accepts non-range values, whereas the implementations used in excel and google sheets do not.

FREQUENCY not working as expected

FREQUENCY() is giving me weird results. I feed in 5 numbers as data, i.e. [ 4, 5, 5, 7, 10 ] and my bins are [ [ 4, 6 ], [ 6, 8 ], [ 8, 10 ], [ 10, 12 ], [ 12, 14 ] ] and I get back [ 1, 2, 0, 1, 0, 1, 0, 0, 0, 0, 0 ].

So with 5 items and with 5 buckets I get 11 values back. This is not how FREQUENCY works in Excel.

Any ideas?

edit: quick fix with lodash (note that if value is same as upper bin value, it will be moved to the next bin):

var frequencies = []
    _.each(bins, b => {
        var frequency = 0
        _.each(values, v => {
            if(b[0] <= v  && b[1] > v) {
                frequency++
            }
        })
        frequencies.push({bin: b, frequency: frequency})
    })

generating formula for RX and Tx exchange between two different equipment not speaking same language

Dear @psq , @hmalphettes , @miguelvps , @joaojeronimo , @Y--

I hope you are well and my best wishes for 2020,

I have an issue #josdejong/mathjs#1699

And maybe you could help me with your library.

Topic translate from different protocols formula .

One of the properties is "Formulas".

Formulas ( Rx / Tx)

• Formulas provide a way to project values received from an equipment to another value range or representation.
• For example, an equipment might send gain values as INTEGERs ranging from 0 to 65535, while the actual gain range in is -64db to 12db. Obviously, the user of a front-end application prefers to deal with the gain values in db instead of the technical INTEGER range.
• To accommodate for this need, I am looking to provides the concept of formulas.

• This will create a basic formula which does not alter the input value – meaning it returns the identity of the input value:

image

Picture from ww.lawo.de

• The input value of the formula is denoted with the symbol $. You can use this symbol in an arithmetic expression which yields the desired output range.
• The line “$ =“ defines the input value (as sent by the device) of the formula.
• The following line “RX($) =“ defines the expression used to convert values that have been received from the device.
• The following line “TX($) =” defines the expression used to convert values that are about to get sent to the device. This expression has to reverse the projection made in the RX expression.

• To follow the ifSpeed example, let’s display the speed of the interface in megabytes per second instead of bits per second:
o Enter a test input value in the “$ =” field, e.g. “10000000” (10 megabit)
o Enter the expression $ / 8000000.0 into the “RX” field. 8000000 is the factor used to turn unit bits into unit megabyte.
o To reverse the RX expression, enter the expression $ * 8000000.0 into the “TX” field.
o You will now see the following:

image

Picture from www.lawo.de

o You can see that the result of the RX expression is 1.25 (megabytes) and the result of the TX expression, which uses 1.25 as input value, is 10000000 (bits per second, which is equal to the input value of the RX expression).

INPUT RANGE

• I have an Analog to Digital convert 12 bits (4096 positions)
• The manufacturer of the A/D converter infor you for 0 = -128dB and for 4095 = +15 dB

I am looking to create as above "Formula" with possibility to select linear or log the Rx and Tx formula.

Data model of my paramater

{
                    "identifier": "ParameTypeStream",
                    "description": "Stream PPM MAIN",
                    "value": 0,
                    "minimum": -4096,
                    "maximum": 480,
                    "access": "read",
                    "format": "%8.2f°",
                    "enumeration": "",
                    "factor": 32,
                    "isOnline": true,
                    "default": -1024,
                    "type": "integer",
                     "formula": "1000*\n1000/"
                }

The properties : formula

The Minimum & Maximum are :

"minimum": -4096,
"maximum": 480,

Then I need to generate the correct formula for Rx & Tx.

Regarding formula "1000\n1000/"*

That means when the client receives this properties the "/n" is the separation from RX formula then TX formula then no needs two properties

Here :

RX = value *1000
TX = value /1000

Use case - write the formula - RX

  1. the client introduces the formula in an editbox. Just the '$' indicates the value I need to passing into the math expression and get the result.

Use case - write the formula - TX

If the RX formula is already written in the editbox , I need and expect with Mathjs library to generate the invert formula for TX and vice-versa if Tx is filled, then I got RX.

If RX = $/1000
then I need to get for TX = $*1000

The formula could be complex (log, square, ^, (expression)*log) I attached a document from my friend written for F# (Microsoft) long time ago and now we are using nodejs and javascript.

Ember+ Formulas.pdf

I hope you could make a simple example of code how to use it and then I will try it ;-)

Best Wishes for 2020
Youssef

BETADIST function does not work correctly

This function does not appear to be working correctly
In FormulaJS:
BETADIST(1/52,0.4,9.6)
FormulaJS = 9.966606842186747
Excel = 0.540601367

Could some one check this out for me.

Community built Formula.js

Dear Sutoiku team @Y-- @AurelienRibon

I started a Github organization to be the future home of Formulajs. The aim is to federates contributions around the project and continue the development and maintenance of the library.

First action was to relaunch a documentation website based on the work you did back in 2015. You can see the result here: https://formulajs.info

The roadmap in the coming month is to gather the improvements made in the main forks of the original project. I started from the Handsontable fork, which seemed to be the most lively project.

If you agree with the new dynamic, I would like to make pull request on your repo to mark it as deprecated and redirect it to the one of the Formulajs organisation. That would also be a pleasure to welcome you as member of this new community.

I look forward hearing from you. Thanks again for the heavy work you did, building this great library!

Nicolas

formula.js on CDN

Hi,

I would like to bring formula.js an hosted CDN repository (for example: https://cdnjs.com or http://www.jsdelivr.com). This might imply some updates of the repository:

  • build files included in the repository
  • reduce slightly the number of dependencies (maybe include bessel into the code) and let numeral, numeric and jStats as external dependencies.

I am ready to create a pull request in this direction and wonder if would fit the current guidelines of the library development?

Thanks in advance.
Nicolas

Build formula.js for the browser

When I run "make build" then I get 4 files in the dist directory. In this directory I get a formula.js and formula.standalone.js which are identical when I diff them.

Is this the process for producing a build for the browser or am I missing something?

NORMDIST can not work.

i write a demo by README sample.

<!-- Numeric -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeric/1.2.6/numeric.min.js"></script>
<!-- Numeral.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/numeral.js/1.4.5/numeral.min.js"></script>
<!-- jStat -->
<script src="https://cdn.jsdelivr.net/jstat/latest/jstat.min.js"></script>

<!-- Finally add formula.js -->
<script src="local-formula-path/formula.js"></script>

<script>
    
        window.onload = function()
        {
            formulajs.NORMDIST(21.2366,formulajs.AVERAGE(22.3016,21.2366), formulajs.STDEV(22.3016,21.2366),1);
        }
    </script>

but throw an exception

Uncaught TypeError: Cannot read property 'normal' of undefined
    at Object.exports.NORM.DIST [as NORMDIST] (formula.js:6481)
    at window.onload (excel.html:25)

it seems to the exception because jstat..

PMT not calculated same as Excel (yes I know it's OpenOffice)

hey, I know this is an OpenOffice port, but I noticed that the implementation doesn't return the same PMT as Excel.

(Excel Example)
rate | time | principle | pmt |  
0.1 | 12 | 2000 | ($293.53) | =PMT(A2,B2,C2)

exports.PMT = function(rate, periods, present, future, type) {
      //formula:
      //PMT = PV x IR / (1 - (1 + IR) -NP)
      //converted to js:
      //PMT = (PV * IR) / (1 - Math.pow(1 + IR, -NP))
      //(ir,np,pv) =>{//(rate, time, principle)
  let pay = (present * rate) / (1 - Math.pow(1 + rate, -periods));
  return -pay;
  //your implementation goes on for additional  work but this was all I needed for mine

I'm comparing the values to an Excel sheet calculating PMT from $100-$5000 for a time period of 1-18 months and the above PMT lines up with Excel through the whole sheet.

Also, though this isn't technically an Excel function, I also use .toMoney to format like excel:

// eslint-disable-next-line
Number.prototype.toMoney = function(decimals, decimal_sep, thousands_sep)
{
     var n = this,
     c = isNaN(decimals) ? 2 : Math.abs(decimals),
     d = decimal_sep || '.',
     t = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
     sign = (n < 0) ? '-' : '',
     // eslint-disable-next-line
     i = parseInt(n = Math.abs(n).toFixed(c)) + '',
     // eslint-disable-next-line
     j = ((j = i.length) > 3) ? j % 3 : 0;
     return sign + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '');
}

Formula js Updates?

When does the below formulas will get implemented in formulajs:
COUPPCD
COUPNCD
PRICE
YIELD

How do i get this to Work

The Documentation is lacking to the point that i am not sure what i need to do to allow this to run on my site. I keep getting the require error. I am sure i need to install something else but if there is more requirements can they please be listed and possibly a simple example would be great. Looks like i need WebPack and Node.JS to get this to run but how would i install it to my project.

bessel functions

Thanks for clarifying on the NEGBINOM issue.

There are bessel functions in Excel (BESSELJ, BESSELY, BESSELI, BESSELK), but according to

formula.js/lib/formula.js

Lines 885 to 900 in 96fa1fe

Formula.BESSELI = function () {
return;
};
Formula.BESSELJ = function () {
return;
};
Formula.BESSELK = function () {
return;
};
Formula.BESSELY = function () {
return;
};
there is no implementation. Am I missing something? I must be, given that your website claims that "JavaScript implementation of all functions supported by Microsoft Excel", but I can't for the life of me find the implementation

FINV

Hi,
I am trying to use the FINV and i get different results using formulaJs and excel.
FINV(0.05,8,22) gives
0.319 in Formula.js and
2.3965 when used in Microsoft Excel.
Am i doing anything wrong?
Thanks
Azeet

jStat.normal no longer exists

The function below uses jStat.normal which doesn't appear to be in the latest version.

 Formula.NORMSDIST = function (z, cumulative) {
      return (cumulative) ? jStat.normal.cdf(z, 0, 1) : jStat.normal.pdf(z, 0, 1);
    };

Error: Cannot set property jStat of Undefined

Hi, I'm using your library within my custom calculators which are built in React.js. When I build and run my project, I get an error : 'cannot set property 'jStat' of undefined'. I suspect that jStat is trying to set a global variable which interferes with how React.js works under the hood. Did anyone run into such an issue before? Where are you implementing jStat? Thank you

Formula.js does not work with jstat 1.0.0

I just found formula.js last week and I am very appreciative of the work that you guys have done to make working with formula easier for the rest of the JS world. I do want to bring to your attention some trouble with getting the library to work.

I followed the instructions and included the latest version of every dependency. When I tried to load the page, the code is throwing an exception on line 3303:

CORREL = jStat.corrcoeff;

The problem is that jStat is undefined. It seems that the namespace for jstat has changed from jStat to jstat in version 1.0.0. Also, a bunch of functions seem to have been moved. I am able to get the code to work if I include the jstat.js file from stoic.com. I am hoping that one of you might have a quick solution for this problem. If not, it might be helpful to update the dependency section to direct people to download the old version of jstat. Let me know if I can assist in fixing this problem.

Suggested SUM Function Update

The following sum function allows the user to send in:

  • a set of individual numbers,
  • an array of numbers,
  • both an array and a set of numbers

and then the function returns the total.

**Note: the function does not check for letters or special characters. It just skips over them.

function SUM(){
var nums = [], res = 0;
for(var i in arguments){
if(Object.prototype.toString.call( arguments[i] ) === '[object Array]'){
// This line will allow multidimensional arrays to be converted to a single dimension array
nums = nums.concat(arguments[i].toString().split(','));
}
if(Object.prototype.toString.call( arguments[i] ) === '[object Number]'){
nums.push(arguments[i]);
}
}
for(var i=0; i<nums.length; i++){
if(isNaN(nums[i]))continue;
res += Number(nums[i]);
}
return res;
}

// Examples

SUM( 5,10,15 ) // Result: 30
SUM( [5,10,15] ) // Result: 30
SUM( 1,1,[5,10,15],3 ) // Result: 35
SUM( a, 1, 3 ) // Result: 4

REGEXEXTRACT

I noticed that REGEXEXTRACT can't handle capture groups. Google handles this as you can see here https://support.google.com/docs/answer/3098244

In their example,
text = "(Content) between brackets"
regex = '(([A-Za-z]+))'

returns
'Content'

I think that if the match call returns more than one element in the array then the first value should be returned instead of the entire match.

Current impl

    Formula.REGEXEXTRACT = function (text, regular_expression) {
      var match = text.match(new RegExp(regular_expression));
      return match ? match[0] : null;
    };

Proposed

    Formula.REGEXEXTRACT = function (text, regular_expression) {
      var match = text.match(new RegExp(regular_expression));
      return match ? (match[match.length > 1 ? match.length - 1 : 0]) : null;
    };

CUMIPMT not give me right answer

i use cumipmt function as disaply in formula.js when it's given right answer when i put month like 1 month 2 month (in int format) but when i pass 1.5, 2.5 then give me a wrong answer . when i compare this answer to excel sheet then i found formula.js return wrong answer
please help !!!!

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.