Num.num_of_string should accept decimal numbers
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Estancado
- Stack tecnológico
- ocaml
- Área
- backend
Línea de trabajo
Start by locating Num.num_of_string and its existing integer-string parsing, then compare it with the sample implementation in the issue. Decimal strings such as "1.5" should parse while existing integer inputs retain their current behavior; verify both cases with the library's tests or interactive examples.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Original bug ID: 4553
Reporter: zack
Status: acknowledged (set by @damiendoligez on 2008-08-04T15:21:21Z)
Resolution: open
Priority: normal
Severity: feature
Version: 3.10.1
Category: otherlibs
Bug description
It seems that Num.num_of_string works only on strings denoting integers:
Num.num_of_string "1.5";;
Exception: Failure "num_of_string".
Supporting decimal numbers appears to be quite easy: numbers such as "1.5" can be mapped to the Ratio.ratio "15/10" and then injected to Num using the Num.Ratio constructor. The change will be backward compatible as the new functionality can be triggered only when the input string contain a '.', situation which currently raise the Failure above.
Can you please consider adding support for decimal numbers in the Num.num_of_string function?
A sample implementation (relying on the current implementation of Num.num_of_string for integer strings) is reported below in the additional information section.
Cheers.
Additional information
let my_num_of_string s =
let dot_pos = try Some (String.index s '.') with Not_found -> None in
match dot_pos with
| None -> Num.num_of_string s
| Some i -> (* e.g.: s = "45.6789", i = 2 )
let len = String.length s in
let numerator = ( e.g. "45" ^ "6789" = "456789" )
String.sub s 0 i ^ String.sub s (i + 1) (len - (i + 1)) in
let denominator = ( e.g. <big_int 10000> *)
Big_int.power_int_positive_int 10 (len - (i + 1)) in
Num.Ratio (Ratio.create_ratio (big_int_of_string numerator) denominator)
- Lenguaje dominante
- OCaml
- Estrellas
- 39
- Forks
- 29
- Métricas de merge de PR
- Sin PR fusionados en 30 d
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
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ocaml/num
-
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
-
documentation
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
martin-stromberg/FinanceManager#562 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
open-telemetry/opentelemetry-zig#193 ·
Los mantenedores suelen responder en 1 día
-
skills: _skill_body cuts the frontmatter short when a description contains ---Posiblemente ocupada @nurlanmnn la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
zilliztech/memsearch#876 ·
Los mantenedores suelen responder en 1 día
-
BitBucketBackend.get_versions does not apply project.version_filterPosiblemente ocupada @muskan-creates352 la tomó hoy. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
fedora-infra/anitya#2209 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día