Num.num_of_string should accept decimal numbers
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Ferma
- Stack tecnologico
- ocaml
- Ambito
- backend
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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)
- Lingua principale
- OCaml
- Stelle
- 39
- Fork
- 29
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ocaml/num
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
-
documentation
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
martin-stromberg/FinanceManager#562 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
open-telemetry/opentelemetry-zig#193 ·
I maintainer di solito rispondono entro 1 giorno
-
skills: _skill_body cuts the frontmatter short when a description contains ---Forse già presa @nurlanmnn l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
zilliztech/memsearch#876 ·
I maintainer di solito rispondono entro 1 giorno
-
BitBucketBackend.get_versions does not apply project.version_filterForse già presa @muskan-creates352 l’ha presa oggi. Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
fedora-infra/anitya#2209 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno