Skip to content

Number literals: parse integer values too large to fit into Decimal as BigInteger (bigint), not Double #13212

@mklement0

Description

@mklement0

Note: This is technically a breaking change, but arguably one that falls into Bucket 3: Unlikely Grey Area.

Summary of the new feature/enhancement

Currently and historically, an integer number literal in source code that is too big (in absolute terms) to fit into [decimal] is parsed as a [double] - this invariably leads to a loss of accuracy:

# 99999999999999999999999999999 is greater than [decimal]::MaxValue, so it is parsed as a [double]
PS> [bigint] 99999999999999999999999999999
99999999999999991433150857216

Given that 7.0 introduced the n suffix to explicitly request a [bigint] and that suffixes are generally optional, with PowerShell picking the appropriate type, it would make sense to parse integer values outside the range of [decimal] as [bigint].

In other words: it would make sense to parse 99999999999999999999999999999 the same as 99999999999999999999999999999n.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Breaking-Changebreaking change that may affect usersIssue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreWG-Languageparser, language semantics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions