Skip to content

Use Rounding_Mode instead of use_bankers flag #12641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 49 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
d89e808
all but doc
GregoryTravis Mar 25, 2025
64127a6
wip
GregoryTravis Mar 25, 2025
57ee98d
add import to Numbers
GregoryTravis Mar 25, 2025
07e91da
wip
GregoryTravis Mar 26, 2025
e5cfcbe
Merge branch 'develop' into wip/gmt/9387-rm
GregoryTravis Mar 26, 2025
0939c5d
Merge branch 'develop' into wip/gmt/9387-rm
GregoryTravis Mar 27, 2025
974e859
added rm import
GregoryTravis Mar 27, 2025
ae33956
Merge branch 'develop' into wip/gmt/9387-rm
GregoryTravis Mar 28, 2025
e246663
typo
GregoryTravis Mar 28, 2025
859cca2
Merge branch 'develop' into wip/gmt/9387-rm
GregoryTravis Mar 31, 2025
d74c53b
wip
GregoryTravis Mar 31, 2025
0c36aa9
proper constructors
GregoryTravis Mar 31, 2025
168b76f
api
GregoryTravis Mar 31, 2025
24778cb
typo
GregoryTravis Mar 31, 2025
2557fef
Merge branch 'develop' into wip/gmt/9387-rm
GregoryTravis Apr 1, 2025
0e91142
wip
GregoryTravis Apr 1, 2025
4e4e0fc
Merge branch 'develop' into wip/gmt/9387-rm
GregoryTravis Apr 1, 2025
29dc9f1
fix
GregoryTravis Apr 1, 2025
5c8b8ab
changelog
GregoryTravis Apr 1, 2025
7fd7664
fmt
GregoryTravis Apr 1, 2025
5be63fe
wip
GregoryTravis Apr 1, 2025
832af0c
Merge branch 'develop' into wip/gmt/9387-rm
GregoryTravis Apr 3, 2025
90b425d
clarified changelog
GregoryTravis Apr 3, 2025
d80aa84
wip
GregoryTravis Apr 3, 2025
3f2ebc6
Merge branch 'develop' into wip/gmt/9387-rm
GregoryTravis Apr 7, 2025
627cab1
handle deprecated argument in Numbers
GregoryTravis Apr 7, 2025
df9486d
decimal, columns
GregoryTravis Apr 7, 2025
5e113ab
Merge branch 'develop' into wip/gmt/9387-rm
GregoryTravis Apr 8, 2025
3837536
api
GregoryTravis Apr 8, 2025
2b5b406
mark db deprecated warning spec pending
GregoryTravis Apr 8, 2025
b6a18df
api
GregoryTravis Apr 8, 2025
9808e51
Use conversion instead of method.
jdunkerley Apr 9, 2025
5bcab3d
Merge branch 'develop' into wip/gmt/9387-rm
GregoryTravis Apr 9, 2025
fdf7814
submodule update
GregoryTravis Apr 9, 2025
b08e419
merge
GregoryTravis Apr 9, 2025
15e5a47
Merge branch 'develop' into wip/gmt/9387-rm
GregoryTravis Apr 9, 2025
e5c354e
api
GregoryTravis Apr 9, 2025
afc577f
removed more Bools
GregoryTravis Apr 9, 2025
2637e4d
submodule update
GregoryTravis Apr 9, 2025
5fbbe9c
disable converison
GregoryTravis Apr 10, 2025
6e700ab
Revert "disable converison"
GregoryTravis Apr 10, 2025
3ae9f3b
Merge branch 'develop' into wip/gmt/9387-rm
GregoryTravis Apr 10, 2025
c356b6a
log
GregoryTravis Apr 10, 2025
316c892
removed self-import
GregoryTravis Apr 10, 2025
246689b
unused import
GregoryTravis Apr 10, 2025
4090a0a
review, logging
GregoryTravis Apr 10, 2025
b3087a9
api
GregoryTravis Apr 10, 2025
c1bcc1d
unused warnings
GregoryTravis Apr 10, 2025
6e3f45e
remove logging
GregoryTravis Apr 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@
- [Added `add_group_number` for Postgres and SQLite.][12574]
- [Added `add_group_number` for Snowflake and SQLServer.][12590]
- [Added Regex_match for Postgres][12663]
- [Replace `use_bankers` flag with `Rounding_Mode` in all `round`
methods][12641]
Comment on lines +143 to +144
Copy link
Member

Choose a reason for hiding this comment

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

Shall we indicate that this is a potentially breaking change?

Copy link
Member

Choose a reason for hiding this comment

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

NetBeans has infrastructure for marking a change as incompatible and then rendering it as highlighted and/or in a special section: https://bits.netbeans.org/10.0/javadoc/org-openide-modules/apichanges.html


[11926]: https://github.com/enso-org/enso/pull/11926
[12031]: https://github.com/enso-org/enso/pull/12031
Expand All @@ -147,6 +149,7 @@
[12574]: https://github.com/enso-org/enso/pull/12574
[12590]: https://github.com/enso-org/enso/pull/12590
[12663]: https://github.com/enso-org/enso/pull/12663
[12641]: https://github.com/enso-org/enso/pull/12641

#### Enso Language & Runtime

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
- pow self exp:Standard.Base.Data.Numbers.Integer -> Standard.Base.Data.Decimal.Decimal
- precision self -> Standard.Base.Data.Numbers.Integer
- remainder self that:Standard.Base.Data.Decimal.Decimal -> Standard.Base.Data.Decimal.Decimal
- round self decimal_places:Standard.Base.Data.Numbers.Integer= use_bankers:Standard.Base.Data.Boolean.Boolean= -> Standard.Base.Data.Decimal.Decimal
- round self decimal_places:Standard.Base.Data.Numbers.Integer= rounding_mode:Standard.Base.Data.Numeric.Rounding_Mode.Rounding_Mode= -> Standard.Base.Data.Decimal.Decimal
- scale self -> Standard.Base.Data.Numbers.Integer
- set_scale self new_scale:Standard.Base.Data.Numbers.Integer -> Standard.Base.Data.Decimal.Decimal
- signum self -> Standard.Base.Data.Numbers.Integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- min_value -> Standard.Base.Any.Any
- negate self -> Standard.Base.Data.Numbers.Float
- parse text:Standard.Base.Data.Text.Text locale:(Standard.Base.Data.Locale.Locale|Standard.Base.Nothing.Nothing)= format:(Standard.Base.Data.Text.Text|Standard.Base.Nothing.Nothing)= -> Standard.Base.Any.Any
- round self decimal_places:Standard.Base.Data.Numbers.Integer= use_bankers:Standard.Base.Data.Boolean.Boolean= -> Standard.Base.Any.Any
- round self decimal_places:Standard.Base.Data.Numbers.Integer= rounding_mode:Standard.Base.Data.Numeric.Rounding_Mode.Rounding_Mode= -> Standard.Base.Any.Any
- to_decimal self -> Standard.Base.Data.Decimal.Decimal
- to_float self -> Standard.Base.Data.Numbers.Float
- truncate self -> Standard.Base.Data.Numbers.Integer
Expand Down Expand Up @@ -47,7 +47,7 @@
- floor self -> Standard.Base.Data.Numbers.Integer
- negate self -> Standard.Base.Data.Numbers.Integer
- parse text:Standard.Base.Data.Text.Text radix:Standard.Base.Data.Numbers.Integer= -> Standard.Base.Any.Any
- round self decimal_places:Standard.Base.Data.Numbers.Integer= use_bankers:Standard.Base.Data.Boolean.Boolean= -> Standard.Base.Any.Any
- round self decimal_places:Standard.Base.Data.Numbers.Integer= rounding_mode:Standard.Base.Data.Numeric.Rounding_Mode.Rounding_Mode= -> Standard.Base.Any.Any
- to_decimal self -> Standard.Base.Data.Decimal.Decimal
- to_float self -> Standard.Base.Data.Numbers.Float
- truncate self -> Standard.Base.Data.Numbers.Integer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Enso Signatures 1.0
## module Standard.Base.Data.Numeric.Rounding_Mode
- type Rounding_Mode
- Value rounding_mode:Standard.Base.Data.Numeric.Rounding_Mode.RoundingMode
- bankers -> Standard.Base.Any.Any
- half_up -> Standard.Base.Any.Any
- Bankers
- Half_Up
- to_java_rounding_mode self -> Standard.Base.Data.Numeric.Rounding_Mode.RoundingMode
11 changes: 6 additions & 5 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Decimal.enso
Original file line number Diff line number Diff line change
Expand Up @@ -991,15 +991,16 @@ type Decimal
Round to a specified number of decimal places.

By default, rounding uses "symmetric round-half-up", also known as
"half-up." If use_bankers=True, then it uses "round-half-even", also
"half-up." If rounding_mode=Rounding_Mode.Bankers, then it uses "round-half-even", also
known as "banker's rounding".

Arguments:
- decimal_places: The number of decimal places to round to. Can be
negative, which results in rounding to positive integer powers of 10.
Must be between Java `Integer.MIN_VALUE` and `Integer.MAX_VALUE`
(-2147483648 and 2147483647) (inclusive).
- use_bankers: Rounds mid-point to nearest even number.
- rounding_mode: specifies how to break ties for the least significant
digit.

! Error Conditions

Expand Down Expand Up @@ -1032,12 +1033,12 @@ type Decimal
> Example
Use Banker's Rounding.

Decimal.new "2.5" . round use_bankers=True
Decimal.new "2.5" . round rounding_mode=Rounding_Mode.Bankers
# => 2
round : Integer -> Boolean -> Decimal
round self (decimal_places:Integer=0) (use_bankers:Boolean=False) -> Decimal =
round self (decimal_places:Integer=0) (rounding_mode:Rounding_Mode=Rounding_Mode.Half_Up) -> Decimal =
out_of_range = decimal_places > Java_Integer.MAX_VALUE || decimal_places < Java_Integer.MIN_VALUE
if out_of_range.not then Decimal.Value (Decimal_Utils.round self.big_decimal decimal_places use_bankers) else
if out_of_range.not then Decimal.Value (Decimal_Utils.round self.big_decimal decimal_places (rounding_mode == Rounding_Mode.Bankers)) else
message = "round decimal_places must be between "+Java_Integer.MIN_VALUE.to_text+" and "+Java_Integer.MAX_VALUE.to_text+" (inclusive), but was "+decimal_places.to_text
Error.throw (Out_Of_Range.Error decimal_places message)

Expand Down
23 changes: 13 additions & 10 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Numbers.enso
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import project.Any.Any
import project.Data.Decimal.Decimal
import project.Data.Locale.Locale
import project.Data.Numeric.Rounding_Mode.Rounding_Mode
import project.Data.Ordering.Comparable
import project.Data.Text.Text
import project.Error.Error
Expand Down Expand Up @@ -659,7 +660,7 @@ type Float
Round to a specified number of decimal places.

By default, rounding uses "symmetric round-half-up", also known as
"half-up." If use_bankers=True, then it uses "round-half-even", also
"half-up." If rounding_mode=Rounding_Mode.Bankers, then it uses "round-half-even", also
known as "banker's rounding".

If `decimal_places` > 0, `round` returns a `Float`; otherwise, it
Expand All @@ -672,7 +673,8 @@ type Float
- decimal_places: The number of decimal places to round to. Can be
negative, which results in rounding to positive integer powers of 10.
Must be between -15 and 15 (inclusive).
- use_bankers: Rounds mid-point to nearest even number.
- rounding_mode: specifies how to break ties for the least significant
digit.

! Error Conditions

Expand Down Expand Up @@ -705,12 +707,12 @@ type Float
> Example
Use Banker's Rounding.

2.5 . round use_bankers=True == 2
2.5 . round rounding_mode=Rounding_Mode.Bankers == 2
round : Integer -> Boolean -> Integer | Float ! Illegal_Argument
round self (decimal_places:Integer=0) (use_bankers:Boolean=False) =
round self (decimal_places:Integer=0) (rounding_mode:Rounding_Mode=Rounding_Mode.Half_Up) =
report_unsupported cp = Error.throw (Illegal_Argument.Error cp.payload.message)
Panic.catch Unsupported_Argument_Types handler=report_unsupported
round_float_builtin self decimal_places use_bankers
round_float_builtin self decimal_places (rounding_mode == Rounding_Mode.Bankers)

## GROUP Operators
ICON operators
Expand Down Expand Up @@ -1074,14 +1076,15 @@ type Integer
argument. For negative decimal places, see below.

By default, rounding uses "symmetric round-half-up", also known as
"half-up." If use_bankers=True, then it uses "round-half-even", also
"half-up." If rounding_mode=Rounding_Mode.Bankers, then it uses "round-half-even", also
known as "banker's rounding".

Arguments:
- decimal_places: The number of decimal places to round to. Can be
negative, which results in rounding to positive integer powers of 10.
Must be between -15 and 15 (inclusive).
- use_bankers: Rounds mid-point to nearest even number.
- rounding_mode: specifies how to break ties for the least significant
digit.

! Error Conditions
If `self` is outside the range -99999999999999..99999999999999
Expand All @@ -1108,14 +1111,14 @@ type Integer
> Example
Round to the nearest hundred, using Banker's Rounding.

12250 . round -2 use_bankers=True == 12200
round self (decimal_places:Integer=0) (use_bankers:Boolean=False) -> Integer ! Illegal_Argument =
12250 . round -2 rounding_mode=Rounding_Mode.Bankers == 12200
round self (decimal_places:Integer=0) (rounding_mode:Rounding_Mode=Rounding_Mode.Half_Up) -> Integer ! Illegal_Argument =
## We reject values outside the range of `long` here, so we don't also
do this check in the Java.
Rounding_Helpers.check_round_input self <|
report_unsupported cp = Error.throw (Illegal_Argument.Error cp.payload.message)
Panic.catch Unsupported_Argument_Types handler=report_unsupported
round_integer_builtin self decimal_places use_bankers
round_integer_builtin self decimal_places (rounding_mode == Rounding_Mode.Bankers)

## GROUP Operators
ICON operators
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Math_Context
specifies exact operations.
- rounding_mode: The rounding mode to use.
new : Integer | Unlimited -> Rounding_Mode -> Math_Context
new (precision : Integer | Unlimited) (rounding_mode : Rounding_Mode = Rounding_Mode.half_up) =
new (precision : Integer | Unlimited) (rounding_mode : Rounding_Mode = Rounding_Mode.Half_Up) =
case precision of
_ : Integer -> Math_Context.Value (MathContext.new precision rounding_mode.rounding_mode)
_ : Unlimited -> Math_Context.Value (MathContext.new 0 rounding_mode.rounding_mode)
_ : Integer -> Math_Context.Value (MathContext.new precision rounding_mode.to_java_rounding_mode)
_ : Unlimited -> Math_Context.Value (MathContext.new 0 rounding_mode.to_java_rounding_mode)
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ polyglot java import java.math.RoundingMode
`Rounding_Mode` is used to specify the method to use for rounding a value in
operations on `Decimal`s.` See `Decimal` for more details.
type Rounding_Mode
## PRIVATE
Value (rounding_mode : RoundingMode)

## ICON math
Round towards positive infinity for positive numbers, and negative
infinity for negative numbers. (This is the default.)
half_up : Rounding_Mode
half_up = Rounding_Mode.Value RoundingMode.HALF_UP
Half_Up

## ICON math
Rownd towards the nearest neighbor, with ties broken by rounding towards
the nearest even neighbor.
bankers : Rounding_Mode
bankers = Rounding_Mode.Value RoundingMode.HALF_EVEN
Bankers

private to_java_rounding_mode self -> RoundingMode =
case self of
Rounding_Mode.Half_Up -> RoundingMode.HALF_UP
Rounding_Mode.Bankers -> RoundingMode.HALF_EVEN
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@
- read self max_rows:Standard.Table.Rows_To_Read.Rows_To_Read= -> Standard.Table.Column.Column
- regex_match self pattern:(Standard.Database.DB_Column.DB_Column|Standard.Base.Data.Text.Text|Standard.Base.Data.Text.Regex.Regex) -> Standard.Database.DB_Column.DB_Column
- rename self name:Standard.Base.Data.Text.Text -> Standard.Base.Any.Any
- round self decimal_places:Standard.Base.Data.Numbers.Integer= use_bankers:Standard.Base.Data.Boolean.Boolean= -> Standard.Base.Any.Any
- round_builtin self decimal_places:Standard.Base.Any.Any use_bankers:Standard.Base.Any.Any -> Standard.Base.Any.Any
- round_decimal self decimal_places:Standard.Base.Any.Any use_bankers:Standard.Base.Any.Any -> Standard.Base.Any.Any
- round_float self decimal_places:Standard.Base.Any.Any use_bankers:Standard.Base.Any.Any -> Standard.Base.Any.Any
- round_integer self decimal_places:Standard.Base.Any.Any use_bankers:Standard.Base.Any.Any -> Standard.Base.Any.Any
- round self decimal_places:Standard.Base.Data.Numbers.Integer= rounding_mode:Standard.Base.Data.Numeric.Rounding_Mode.Rounding_Mode= -> Standard.Base.Any.Any
- round_builtin self decimal_places:Standard.Base.Any.Any rounding_mode:Standard.Base.Any.Any -> Standard.Base.Any.Any
- round_decimal self decimal_places:Standard.Base.Any.Any rounding_mode:Standard.Base.Any.Any -> Standard.Base.Any.Any
- round_float self decimal_places:Standard.Base.Any.Any rounding_mode:Standard.Base.Any.Any -> Standard.Base.Any.Any
- round_integer self decimal_places:Standard.Base.Any.Any rounding_mode:Standard.Base.Any.Any -> Standard.Base.Any.Any
- second self -> Standard.Base.Any.Any
- short_circuit_special_floating_point self exp:Standard.Base.Any.Any -> Standard.Base.Any.Any
- should_be_selected_by_type self value_type:Standard.Table.Value_Type.Value_Type -> Standard.Base.Data.Boolean.Boolean
- should_use_builtin_round self decimal_places:Standard.Base.Any.Any use_bankers:Standard.Base.Any.Any -> Standard.Base.Any.Any
- should_use_builtin_round self decimal_places:Standard.Base.Any.Any rounding_mode:Standard.Base.Any.Any -> Standard.Base.Any.Any
- sort self order:Standard.Base.Data.Sort_Direction.Sort_Direction= -> Standard.Database.DB_Column.DB_Column
- sql_type self -> Standard.Base.Any.Any
- starts_with self other:(Standard.Database.DB_Column.DB_Column|Standard.Base.Data.Text.Text|Standard.Base.Any.Any) case_sensitivity:Standard.Base.Data.Text.Case_Sensitivity.Case_Sensitivity= -> Standard.Database.DB_Column.DB_Column
Expand Down
Loading
Loading