Extracting the real and imaginary part of a complex number
- Dominant language
- Swift
- Stars
- 1.9k
- Forks
- 181
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 6
Description
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.
Contributor guide
Research direction
Start at the real and imaginary property implementations shown in the issue and inspect how they handle complex values containing infinity or NaN. The work is done when each property returns its own component independently, preserving finite, infinite, and NaN values correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100