Skip to content

Commit

Permalink
Fix Number.significant to return 0 as is, not as Float64 (cryst…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sija authored Oct 24, 2021
1 parent dfa28a4 commit 0aa45ce
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
1 change: 1 addition & 0 deletions spec/std/number_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe "Number" do
it "preserves type" do
123.significant(2).should eq(120)
123.significant(2).should be_a(Int32)
0.significant(1).should be_a(Int32)
end
end

Expand Down
5 changes: 1 addition & 4 deletions src/number.cr
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,10 @@ struct Number
if digits < 0
raise ArgumentError.new "digits should be non-negative"
end
return self if zero?

x = self.to_f

if x == 0
return x
end

if base == 10
log = Math.log10(self.abs)
elsif base == 2
Expand Down

0 comments on commit 0aa45ce

Please sign in to comment.