tscircuit / tscircuit/math-utils

range() with a fractional step emits an extra element past the exclusive end

Open Beginner friendly
#38 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
0
Forks
11
PR merge metrics
No merged PRs in 30d

Description

range(0, 1, 0.1) returns 11 elements instead of 10 — the loop accumulates i += step, so float drift lands the last value at ~0.9999999999999999, which slips under the exclusive end 1.0 and gets pushed. range(0, 3, 0.3) has the same off-by-one (11 vs 10). Integer steps are fine. Computing each element as start + k * step (with k < ceil((end - start) / step)) avoids the drift. Repro + fix PRs to follow.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the TypeScript implementation of range() and reproduce the fractional-step cases from the issue, including range(0, 1, 0.1) and range(0, 3, 0.3). Add regression coverage for the exclusive-end behavior and verify that fractional ranges no longer emit an extra element while integer steps remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.