Skip to content

Extracting the real and imaginary part of a complex number #288

Description

@Dr-Wizard

The real and imaginary part of a complex number are extracted as follows:

public var real: RealType {
@_transparent
get { isFinite ? x : .nan }

@_transparent
set { x = newValue }

}

public var imaginary: RealType {
@_transparent
get { isFinite ? y : .nan }

@_transparent
set { y = newValue }

}

By checking for isFinite can give wrong values, since infinity is not returned correctly as eg. 1/0 is not .nan but .inf. In a complex number, one part can have a regular value while the other is infinite or nan. With the isFinite check, nan is returned for both parts as soon as one of the two parts is not a regular number. (inf or nan) I suggest returning x and y without the isFinite check.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions