Skip to content

Conversation

midichef
Copy link
Contributor

@midichef midichef commented Oct 13, 2025

When plotting a graph, the plotter tries to prevent xmin == xmax by expanding the range. It adds 1 to xmax in that situation. (We ran into this problem before in #1673.) But that fails for large floats, because adding 1 leaves the number unchanged, as in x=2**53; float(x) == float(x + 1). (Because math.ulp(2**53) is 2.0.)

Example, when plotting the first 2 or last 2 lines of this data with .:

x,y
9007199254740992,1
9007199254740992,2
1,9007199254740992
2,9007199254740992

visidata 3.3 gives ZeroDivisionError: float division by zero because the width or height of the box is zero when xmin == xmax or ymin == ymax:

File "/home/midichef/.venv/lib/python3.12/site-packages/visidata/canvas.py", line 648, in xScaler
    xratio = self.plotviewBox.w/(self.canvasBox.w*self.xzoomlevel)

and

File "/home/midichef/.venv/lib/python3.12/site-packages/visidata/canvas.py", line 657, in yScaler
    yratio = self.plotviewBox.h/(self.canvasBox.h*self.yzoomlevel)

This PR handles the case of such large floats.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant