Num.num_of_string should accept decimal numbers
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- ocaml
- 领域
- backend
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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)
- 主要语言
- OCaml
- 星标
- 39
- 派生
- 29
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ocaml/num 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 35/100
-
难度 2/5 1-3 小时 新手友好度 45/100
-
documentation
难度 4/5 3-5 天 新手友好度 35/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
martin-stromberg/FinanceManager#562 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
open-telemetry/opentelemetry-zig#193 ·
维护者通常 1 天内回复
-
skills: _skill_body cuts the frontmatter short when a description contains ---可能已有人在做 @nurlanmnn 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
zilliztech/memsearch#876 ·
维护者通常 1 天内回复
-
BitBucketBackend.get_versions does not apply project.version_filter可能已有人在做 @muskan-creates352 今天认领。 未关闭
难度 1/5 1 小时以内 新手友好度 88/100
fedora-infra/anitya#2209 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复