mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 05:25:28 +03:00
core: add Float.from-string and Double.from-string
This commit is contained in:
parent
1cc751afbb
commit
c0c31b6ad1
@ -189,6 +189,7 @@
|
||||
(defmodule Float
|
||||
(register str (Fn [Float] String))
|
||||
(register format (Fn [&String Float] String))
|
||||
(register from-string (λ [&String] Float))
|
||||
)
|
||||
|
||||
(defmodule Long
|
||||
@ -200,6 +201,7 @@
|
||||
(defmodule Double
|
||||
(register str (Fn [Double] String))
|
||||
(register format (Fn [&String Double] String))
|
||||
(register from-string (λ [&String] Double))
|
||||
)
|
||||
|
||||
(defmodule Char
|
||||
|
@ -199,6 +199,10 @@ String Double_format(const String *s, double x) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
double Double_from_MINUS_string(const String *s) {
|
||||
return strtod(*s, NULL);
|
||||
}
|
||||
|
||||
String Float_str(float x) {
|
||||
int size = snprintf(NULL, 0, "%gf", x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
@ -213,6 +217,10 @@ String Float_format(const String *str, float x) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
float Float_from_MINUS_string(const String *s) {
|
||||
return strtof(*s, NULL);
|
||||
}
|
||||
|
||||
String Int_str(int x) {
|
||||
int size = snprintf(NULL, 0, "%d", x) + 1;
|
||||
String buffer = CARP_MALLOC(size);
|
||||
|
@ -101,4 +101,10 @@
|
||||
0l
|
||||
(to-bytes 0.0)
|
||||
"to-bytes works as expected II"
|
||||
))
|
||||
)
|
||||
(assert-equal test
|
||||
10.3
|
||||
(from-string "10.3")
|
||||
"from-string works as expected"
|
||||
)
|
||||
)
|
||||
|
@ -107,4 +107,10 @@
|
||||
0
|
||||
(to-bytes 0.0f)
|
||||
"to-bytes works as expected II"
|
||||
))
|
||||
)
|
||||
(assert-equal test
|
||||
10.3f
|
||||
(from-string "10.3")
|
||||
"from-string works as expected"
|
||||
)
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user