Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Complex & Quaternion Specified Precision Initialization does not compile

Open 13419596 opened this issue 3 years ago • 1 comments

Context

It is expected that complex/quaternion specified precision types can be initialized using braces. At the moment the compiler complains with the following message Illegal compound literal, complex64 cannot be used as a compound literal with fields etc for the all the specified precision complex and quaternion types.

Code that should compile fine

{
  a := complex128{1., 2.}
  b := complex64{1., 2.}
  q := quaternion128{1., 2., 3., 4.}
  q := quaternion256{1., 2., 3., 4.}
}

Odin Report

	Odin: dev-2022-09:eb0d7465
	OS:   macOS Monterey 12.5 (build: 21G115, kernel: 21.6.0)
	CPU:  ARM64
	RAM:  16384 MiB

Workaround

It is possible to create specified precision complex/quaternion variables, they must first be initialized as unspecified version and then casted to the desired precision

c := complex64(complex(1., 2.))
q := quaternion128(quaternion(1., 2., 3., 4.,))

13419596 avatar Sep 25 '22 21:09 13419596

This is still a problem as of current odin - 2022/10/24

Odin Report

	Odin: dev-2022-10:a5f8c3f6
	OS:   macOS Monterey 12.5 (build: 21G115, kernel: 21.6.0)
	CPU:  ARM64
	RAM:  16384 MiB

Code:

package main

main :: proc()
{
  a := complex128(1.,2.)
  b := complex64(1.,2.)
  c := complex32(1.,2.)
  q0 := quaternion64(1., 2., 3., 4.)
  q1 := quaternion128(1., 2., 3., 4.)
  q2 := quaternion256(1., 2., 3., 4.)
}

output:

Too many arguments in conversion to 'complex128'
``` etc.

13419596 avatar Oct 24 '22 19:10 13419596