Skip to content

Conversation

@jrudder
Copy link
Contributor

@jrudder jrudder commented May 24, 2025

Add round and sumAll functions to BigDecimal

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

The round function supports rounding at an arbitrary scale/position and the following 10 rounding modes:

  • ceil: round towards positive infinity
  • floor: round towards negative infinity
  • to-zero: round towards zero
  • from-zero: round away from zero
  • half-ceil: round to the nearest neighbor; if equidistant round towards positive infinity
  • half-floor: round to the nearest neighbor; if equidistant round towards negative infinity
  • half-to-zero: round to the nearest neighbor; if equidistant round towards zero
  • half-from-zero: round to the nearest neighbor; if equidistant round away from zero
  • half-even: round to the nearest neighbor; if equidistant round to the neighbor with an even digit at the specified scale
  • half-odd: round to the nearest neighbor; if equidistant round to the neighbor with an odd digit at the specified scale

The default scale is 0 (round to integer), and the default mode is half-from-zero.

The sumAll function mirrors that of BigInt.sumAll.

Related

None

jrudder added 2 commits May 23, 2025 21:02
The `round` function supports rounding at an arbitrary scale/position and 10 rounding mode:
 - `ceil`: round towards positive infinity
 - `floor`: round towards negative infinity
 - `to-zero`: round towards zero
 - `from-zero`: round away from zero
 - `half-ceil`: round to the nearest neighbor; if equidistant round towards positive infinity
 - `half-floor`: round to the nearest neighbor; if equidistant round towards negative infinity
 - `half-to-zero`: round to the nearest neighbor; if equidistant round towards zero
 - `half-from-zero`: round to the nearest neighbor; if equidistant round away from zero
 - `half-even`: round to the nearest neighbor; if equidistant round to the neighbor with an even digit
 - `half-odd`: round to the nearest neighbor; if equidistant round to the neighbor with an odd digit

The default scale is `0` (round to integer), and the default mode is `half-from-zero`.
@jrudder jrudder requested a review from mikearnaldi as a code owner May 24, 2025 04:18
@github-project-automation github-project-automation bot moved this to Discussion Ongoing in PR Backlog May 24, 2025
@changeset-bot
Copy link

changeset-bot bot commented May 24, 2025

🦋 Changeset detected

Latest commit: b4d1d24

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 32 packages
Name Type
effect Minor
@effect/cli Major
@effect/cluster Major
@effect/experimental Major
@effect/opentelemetry Major
@effect/platform-browser Major
@effect/platform-bun Major
@effect/platform-node-shared Major
@effect/platform-node Major
@effect/platform Major
@effect/printer-ansi Major
@effect/printer Major
@effect/rpc Major
@effect/sql-clickhouse Major
@effect/sql-d1 Major
@effect/sql-drizzle Major
@effect/sql-kysely Major
@effect/sql-libsql Major
@effect/sql-mssql Major
@effect/sql-mysql2 Major
@effect/sql-pg Major
@effect/sql-sqlite-bun Major
@effect/sql-sqlite-do Major
@effect/sql-sqlite-node Major
@effect/sql-sqlite-react-native Major
@effect/sql-sqlite-wasm Major
@effect/sql Major
@effect/typeclass Major
@effect/vitest Major
@effect/ai Major
@effect/ai-anthropic Major
@effect/ai-openai Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-bot effect-bot changed the base branch from main to next-minor May 24, 2025 04:18
@fubhy
Copy link
Member

fubhy commented May 24, 2025

Thanks! Support for rounding has been sorely missing.

Copy link
Member

@fubhy fubhy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make these rounding functions dual (data last)

@github-project-automation github-project-automation bot moved this from Discussion Ongoing to Waiting on Author in PR Backlog May 24, 2025
@effect-bot effect-bot force-pushed the next-minor branch 4 times, most recently from 59ef614 to 7d8c110 Compare May 24, 2025 09:18
@jrudder
Copy link
Contributor Author

jrudder commented May 24, 2025

@fubhy Thank you for looking into this so quickly.

I have now:

  • updated the functions to use dual
  • cleaned up the JSDoc examples
  • changed digitAt to use self (like the existing normalize and other functions, including the others I added)

@jrudder jrudder requested a review from fubhy May 24, 2025 16:21
@jrudder
Copy link
Contributor Author

jrudder commented May 24, 2025

This last fix to the docs should get the builds working. Please let me know if there are any other changes you would like to see.

Copy link
Member

@fubhy fubhy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Thanks!

@github-project-automation github-project-automation bot moved this from Waiting on Author to Needs merge in PR Backlog May 25, 2025
@fubhy fubhy merged commit ef92259 into Effect-TS:next-minor May 25, 2025
11 checks passed
@github-project-automation github-project-automation bot moved this from Needs merge to Done in PR Backlog May 25, 2025
@effect-bot effect-bot mentioned this pull request May 25, 2025
effect-bot pushed a commit that referenced this pull request May 26, 2025
Co-authored-by: Sebastian Lorenz <fubhy@fubhy.com>
effect-bot pushed a commit that referenced this pull request May 27, 2025
Co-authored-by: Sebastian Lorenz <fubhy@fubhy.com>
effect-bot pushed a commit that referenced this pull request May 27, 2025
Co-authored-by: Sebastian Lorenz <fubhy@fubhy.com>
effect-bot pushed a commit that referenced this pull request May 27, 2025
Co-authored-by: Sebastian Lorenz <fubhy@fubhy.com>
effect-bot pushed a commit that referenced this pull request May 27, 2025
Co-authored-by: Sebastian Lorenz <fubhy@fubhy.com>
effect-bot pushed a commit that referenced this pull request May 27, 2025
Co-authored-by: Sebastian Lorenz <fubhy@fubhy.com>
tim-smart pushed a commit that referenced this pull request May 27, 2025
Co-authored-by: Sebastian Lorenz <fubhy@fubhy.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants