Fields that look like numbers compare as strings

Abierto
#150 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
rust
Área
cli

Línea de trabajo

Start with the three one-liners in the report and confirm the byte-wise comparison. Then find where AwkValue::StrNum is defined and where record fields are turned into plain strings, since the report says nothing creates StrNum yet. Agree on the approach with the maintainers before editing, because the report asks whether StrNum is the intended design. Done when the three commands match gawk and fields like 1.0 and 50 compare numerically.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

$1 > 100 keeps 50, and $1 == 1 drops 1.0:

$ printf '50 150\n1.0 2\n10 9\n' | awk '$1 > 100'
50 150
$ printf '50 150\n1.0 2\n10 9\n' | awk '$1 == 1'
$ printf '50 150\n1.0 2\n10 9\n' | awk '$1 < $2'
1.0 2
10 9

gawk 5.3.2, mawk and nawk print nothing, 1.0 2, and 50 150 / 1.0 2.

POSIX makes a field that looks like a number a numeric string, so it compares numerically with a number or with another numeric string. Here every field is a plain string (typeof($2) on x 10 prints string; gawk prints strnum), so these comparisons are done byte by byte. The same rule covers getline var, split() elements, ARGV, ENVIRON and -v values.

AwkValue::StrNum exists but nothing creates it yet, so this looks like the planned place for it. Is that the plan? I can send a PR for fields if a direction is agreed.

Checked on main 8f8cf8d.

Lenguaje dominante
Rust
Estrellas
31
Forks
13
Merge medio
23 h 42 min
PR fusionados (30 d)
29

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de uutils/awk

Todos los issues de uutils/awk

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.