Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Complex#to_i128, Complex#to_u128 #13838

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions spec/std/complex_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ end
describe "Complex" do
describe "as numbers" do
it_can_convert_between([Complex], [Complex])
it_can_convert_between({{BUILTIN_NUMBER_TYPES_LTE_64}}, [Complex])
it_can_convert_between([Complex], {{BUILTIN_NUMBER_TYPES_LTE_64}})
# TODO pending conversion between Int128
it_can_convert_between({{BUILTIN_NUMBER_TYPES}}, [Complex])
it_can_convert_between([Complex], {{BUILTIN_NUMBER_TYPES}})

division_between_returns {{BUILTIN_NUMBER_TYPES}}, [Complex], Complex
division_between_returns [Complex], {{BUILTIN_NUMBER_TYPES}}, Complex
Expand Down
24 changes: 3 additions & 21 deletions src/complex.cr
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,14 @@ struct Complex
@real
end

# Returns the value as a `Float32` if possible (the imaginary part should be exactly zero),
# raises otherwise.
def to_f32 : Float32
to_f64.to_f32
end

# See `#to_f64`.
def to_f
to_f64
end

# Returns the value as an `Int64` if possible (the imaginary part should be exactly zero),
# raises otherwise.
def to_i64 : Int64
to_f64.to_i64
end

delegate to_i32, to_i16, to_i8, to: to_i64

# Returns the value as an `UInt64` if possible (the imaginary part should be exactly zero),
# raises otherwise.
def to_u64 : UInt64
to_f64.to_u64
end

delegate to_u32, to_u16, to_u8, to: to_u64
delegate to_i128, to_i64, to_i32, to_i16, to_i8, to: to_f64
delegate to_u128, to_u64, to_u32, to_u16, to_u8, to: to_f64
delegate to_f32, to: to_f64

# See `#to_i32`.
def to_i
Expand Down