GithubHelp home page GithubHelp logo

Comments (6)

severo avatar severo commented on April 27, 2024 1

I found the case while wanting to transform a domain extent (that accepts -Infinity and Infinity as valid) to a range extent, something like:

[-Infinity, Infinity].map(d3.scaleLinear())

and I expected having [-Infinity, Infinity] as the output, but got [NaN, NaN] instead.

It's not difficult to test for this case in my application, but I was wondering if it was the "normal" behavior. If it is, OK for me to close the issue.

from d3-interpolate.

severo avatar severo commented on April 27, 2024

Related to #73

from d3-interpolate.

severo avatar severo commented on April 27, 2024

Two possible implementations as discussed on https://d3js.zulipchat.com/#narrow/stream/273725-D3/topic/d3-scale

isFinite(t) ? a * (1 - t) + b * t : (b - a) * t + a

and

(t * t !== Infinity) ? a * (1 - t) + b * t : (b - a) * t + a

from d3-interpolate.

mbostock avatar mbostock commented on April 27, 2024

It’s doing exactly what it’s documented to do, so I’m not sure I consider this a bug. 0 * Infinity is NaN. Why is it useful to support Infinity?

from d3-interpolate.

severo avatar severo commented on April 27, 2024

For the record, another possible implementation by Jacob Rus:

lerp = (a, b, t) => {
  var y = a * (1 - t) + b * t;
  return (y === y) ? y : (b - a) * t
}

from d3-interpolate.

jrus avatar jrus commented on April 27, 2024

It’s doing exactly what it’s documented to do, so I’m not sure I consider this a bug. 0 * Infinity is NaN. Why is it useful to support Infinity?

This scale is a way of defining a certain linear function f. In the event that the slope is not 0, f(∞) should theoretically be ±∞, not undefined.

(Whether it is important or useful to support this edge case is debatable.)

from d3-interpolate.

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.