| Anonymous | Login | Signup for a new account | 2013-05-20 19:35 CEST | ![]() |
| Main | My View | View Issues | Change Log | Roadmap |
| View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | ||||||
| 0004553 | OCaml | OCaml general | public | 2008-05-08 15:02 | 2008-08-04 17:21 | ||||||
| Reporter | zack | ||||||||||
| Assigned To | |||||||||||
| Priority | normal | Severity | feature | Reproducibility | always | ||||||
| Status | acknowledged | Resolution | open | ||||||||
| Platform | OS | OS Version | |||||||||
| Product Version | 3.10.1 | ||||||||||
| Target Version | Fixed in Version | ||||||||||
| Summary | 0004553: Num.num_of_string should accept decimal numbers | ||||||||||
| 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) | ||||||||||
| Tags | No tags attached. | ||||||||||
| Attached Files | |||||||||||
Issue History |
|||
| Date Modified | Username | Field | Change |
| 2008-05-08 15:02 | zack | New Issue | |
| 2008-08-04 17:21 | doligez | Severity | minor => feature |
| 2008-08-04 17:21 | doligez | Status | new => acknowledged |
| 2008-08-04 17:21 | doligez | Additional Information Updated | |
| Copyright © 2000 - 2011 MantisBT Group |