Skip to content

Commit

Permalink
Add Complex#to_i128, Complex#to_u128 (crystal-lang#13838)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored and Blacksmoke16 committed Dec 11, 2023
1 parent bbd0141 commit 2e8ee09
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 24 deletions.
5 changes: 2 additions & 3 deletions spec/std/complex_spec.cr
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
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

0 comments on commit 2e8ee09

Please sign in to comment.