Skip to content

Resolve decimal problem #11

@sjkaliski

Description

@sjkaliski

So I started writing tests for calculus.

Here's an example:

var assert = require('assert');
var numeric = require('../index.js');
var calculus = numeric.calculus;

suite('numeric', function() {

  test('pointDiff should return the derivative at a point, provided function', function(done) {
    var func = function(x) {
      return 2 * x + 2;
    };

    assert.equal(2, calculus.pointDiff(func, 5));
    done();
  });

});

Now, the point derivative of 2x + 2 at any value is 2. The method returns the following: 1.9999999999242843

This is "basically" 2, but it won't pass tests. So I've considered two options:

  1. Handle this decimal stuff
  2. Set an error bound, which the user passes along when including numeric.

I like two more, although it certainly is going to be a hassle to set up. But this way we can have an "acceptable" error bound, which is sustainable and acceptable for the browser, and has minimal effect in performance or large scale operations.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions