Skip to content

Commit 41d6933

Browse files
committed
Remove situations where we're comparing floats with == (Fixes #819)
1 parent a3b703b commit 41d6933

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

examples/example_3/rakefile_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def compile(file, defines = [])
134134
if $cfg[:tools][:test_compiler][:executable] =~ /gcc/
135135
$cfg[:tools][:test_compiler][:arguments] |= ['-Wno-misleading-indentation']
136136
end
137-
cmd_str = build_command_string($cfg[:tools][:test_compiler], [file, out_file], defines)
137+
cmd_str = build_command_string($cfg[:tools][:test_compiler], [file, out_file], defines)
138138
execute(cmd_str)
139139
out_file
140140
end

src/unity.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,17 @@ void UnityPrintFloat(const UNITY_DOUBLE input_number)
445445
}
446446

447447
/* round to nearest integer */
448-
n = ((UNITY_INT32)(number + number) + 1) / 2;
448+
{
449+
UNITY_DOUBLE two_number = number + number;
450+
UNITY_INT32 two_n_trunc = (UNITY_INT32)two_number;
451+
n = (two_n_trunc + 1) / 2;
449452

450453
#ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO
451-
/* round to even if exactly between two integers */
452-
if ((n & 1) && (UNITY_ABS((UNITY_DOUBLE)n - number - 0.5f) < epsilon))
453-
n--;
454+
/* round to even if exactly between two integers */
455+
if ((n & 1) && (two_n_trunc & 1) && !((UNITY_DOUBLE)two_n_trunc < two_number))
456+
n--;
454457
#endif
458+
}
455459

456460
n += n_int;
457461

0 commit comments

Comments
 (0)