Skip to content

Commit

Permalink
pkg/strconv: remove ParseComplex
Browse files Browse the repository at this point in the history
The CUE input

    import "strconv"
    complex: strconv.ParseComplex("+3i", 64)

fails on master as well as v0.10.0 and older versions like v0.8.2:

    complex: unsupported Go type (complex128)

This is because strconv.ParseComplex returns a complex128 Go value,
and the internal/core/convert logic used to translate from Go values
to CUE values does not handle complex128, given that CUE does not have
direct support for complex numbers in the language spec.

One option would be to rewrite strconv.ParseComplex to return a string,
as a form of validator which would canonicalize complex number strings.
This is how CUE's time.Parse API works; it returns a string
given that the CUE language does not have direct support for timestamps.

However, given that strconv.ParseComplex never worked,
and it's not clear that it is needed, particularly as noone complained,
remove it for the time being. Remove the switch case in pkg/gen.go too.

Signed-off-by: Daniel Martí <[email protected]>
Change-Id: I96e327a61bbc5e9a620214540f7402131aa3f793
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1201115
Unity-Result: CUE porcuepine <[email protected]>
Reviewed-by: Roger Peppe <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
mvdan committed Sep 16, 2024
1 parent 7a26789 commit 6280b9e
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 39 deletions.
2 changes: 0 additions & 2 deletions pkg/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,6 @@ func (g *generator) adtKind(typ types.Type) string {
return "adt.IntKind"
case "Float64", "BigFloat", "Decimal":
return "adt.NumberKind"
case "Complex128":
return "adt.TopKind" // TODO(mvdan): what should we return here?
case "DecimalList", "StringList", "CueList":
return "adt.ListKind"
case "Bytes", "Reader":
Expand Down
13 changes: 0 additions & 13 deletions pkg/strconv/pkg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions pkg/strconv/strconv.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,6 @@ func FormatBool(b bool) string {
return strconv.FormatBool(b)
}

// ParseComplex converts the string s to a complex number
// with the precision specified by bitSize: 64 for complex64, or 128 for complex128.
// When bitSize=64, the result still has type complex128, but it will be
// convertible to complex64 without changing its value.
//
// The number represented by s must be of the form N, Ni, or N±Ni, where N stands
// for a floating-point number as recognized by ParseFloat, and i is the imaginary
// component. If the second N is unsigned, a + sign is required between the two components
// as indicated by the ±. If the second N is NaN, only a + sign is accepted.
// The form may be parenthesized and cannot contain any spaces.
// The resulting complex number consists of the two components converted by ParseFloat.
//
// The errors that ParseComplex returns have concrete type *NumError
// and include err.Num = s.
//
// If s is not syntactically well-formed, ParseComplex returns err.Err = ErrSyntax.
//
// If s is syntactically well-formed but either component is more than 1/2 ULP
// away from the largest floating point number of the given component's size,
// ParseComplex returns err.Err = ErrRange and c = ±Inf for the respective component.
func ParseComplex(s string, bitSize int) (complex128, error) {
return strconv.ParseComplex(s, bitSize)
}

// ParseFloat converts the string s to a floating-point number
// with the precision specified by bitSize: 32 for float32, or 64 for float64.
// When bitSize=32, the result still has type float64, but it will be
Expand Down

0 comments on commit 6280b9e

Please sign in to comment.