atoc.mx raw

   1  // Copyright 2020 The Go Authors. All rights reserved.
   2  // Use of this source code is governed by a BSD-style
   3  // license that can be found in the LICENSE file.
   4  
   5  package strconv
   6  
   7  import "internal/stringslite"
   8  
   9  const fnParseComplex = "ParseComplex"
  10  
  11  // convErr splits an error returned by parseFloatPrefix
  12  // into a syntax or range error for ParseComplex.
  13  func convErr(err error, s []byte) (syntax, range_ error) {
  14  	if x, ok := err.(*NumError); ok {
  15  		x.Func = fnParseComplex
  16  		x.Num = stringslite.Clone(s)
  17  		if x.Err == ErrRange {
  18  			return nil, x
  19  		}
  20  	}
  21  	return err, nil
  22  }
  23  
  24  // ParseComplex converts the string s to a complex number
  25  // with the precision specified by bitSize: 64 for complex64, or 128 for complex128.
  26  // When bitSize=64, the result still has type complex128, but it will be
  27  // convertible to complex64 without changing its value.
  28  //
  29  // The number represented by s must be of the form N, Ni, or N±Ni, where N stands
  30  // for a floating-point number as recognized by [ParseFloat], and i is the imaginary
  31  // component. If the second N is unsigned, a + sign is required between the two components
  32  // as indicated by the ±. If the second N is NaN, only a + sign is accepted.
  33  // The form may be parenthesized and cannot contain any spaces.
  34  // The resulting complex number consists of the two components converted by ParseFloat.
  35  //
  36  // The errors that ParseComplex returns have concrete type [*NumError]
  37  // and include err.Num = s.
  38  //
  39  // If s is not syntactically well-formed, ParseComplex returns err.Err = ErrSyntax.
  40  //
  41  // If s is syntactically well-formed but either component is more than 1/2 ULP
  42  // away from the largest floating point number of the given component's size,
  43  // ParseComplex returns err.Err = ErrRange and c = ±Inf for the respective component.
  44  func ParseComplex(s []byte, bitSize int) (float64, float64, error) {
  45  	panic("moxie: complex numbers not supported")
  46  }
  47