Num.num_of_string should accept decimal numbers
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- ocaml
- Lĩnh vực
- backend
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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)
- Ngôn ngữ chính
- OCaml
- Star
- 39
- Fork
- 29
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ocaml/num
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
-
documentation
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
martin-stromberg/FinanceManager#562 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
open-telemetry/opentelemetry-zig#193 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
skills: _skill_body cuts the frontmatter short when a description contains ---Có thể đã có người làm @nurlanmnn đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
zilliztech/memsearch#876 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
BitBucketBackend.get_versions does not apply project.version_filterCó thể đã có người làm @muskan-creates352 đã nhận hôm nay. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
fedora-infra/anitya#2209 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày