Skip to content

Commit 8502a54

Browse files
author
Maxime Chevalier-Boisvert
authored
YJIT: small fix to stats formatting. (ruby#12282)
Avoid division by zero and NaN%, e.g. num_throw_break: 0 ( NaN%) num_throw_retry: 0 ( NaN%) num_throw_return: 0 ( NaN%)
1 parent c45503f commit 8502a54

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

yjit.rb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,9 +521,14 @@ def format_number(pad, number) # :nodoc:
521521
# Format a number along with a percentage over a total value
522522
def format_number_pct(pad, number, total) # :nodoc:
523523
padded_count = format_number(pad, number)
524-
percentage = number.fdiv(total) * 100
525-
formatted_pct = "%4.1f%%" % percentage
526-
"#{padded_count} (#{formatted_pct})"
524+
525+
if total != 0
526+
percentage = number.fdiv(total) * 100
527+
formatted_pct = "%4.1f%%" % percentage
528+
"#{padded_count} (#{formatted_pct})"
529+
else
530+
"#{padded_count}"
531+
end
527532
end
528533

529534
# :startdoc:

0 commit comments

Comments
 (0)