Skip to content

Commit 22bd929

Browse files
committed
awk: numeric string are compared as numbers
1 parent 3fc0f46 commit 22bd929

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

awk/src/interpreter/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,11 @@ macro_rules! compare_op {
12221222
$stack.push_value(bool_to_f64(lhs $op rhs))?;
12231223
}
12241224
(AwkValueVariant::String(lhs), AwkValueVariant::String(rhs)) => {
1225-
$stack.push_value(bool_to_f64(lhs.as_str() $op rhs.as_str()))?;
1225+
if lhs.is_numeric && rhs.is_numeric {
1226+
$stack.push_value(bool_to_f64(strtod(lhs) $op strtod(rhs)))?;
1227+
} else {
1228+
$stack.push_value(bool_to_f64(lhs.as_str() $op rhs.as_str()))?;
1229+
}
12261230
}
12271231
(AwkValueVariant::Number(lhs), AwkValueVariant::UninitializedScalar) => {
12281232
$stack.push_value(bool_to_f64(*lhs $op 0.0))?;

0 commit comments

Comments
 (0)