aboutsummaryrefslogtreecommitdiff
path: root/src/compile/promotions.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/compile/promotions.c')
-rw-r--r--src/compile/promotions.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/compile/promotions.c b/src/compile/promotions.c
index a13108e5..a4d6b9b3 100644
--- a/src/compile/promotions.c
+++ b/src/compile/promotions.c
@@ -3,6 +3,7 @@
#include "../ast.h"
#include "../environment.h"
#include "../stdlib/datatypes.h"
+#include "../stdlib/reals.h"
#include "../stdlib/text.h"
#include "../typecheck.h"
#include "../types.h"
@@ -139,8 +140,11 @@ Text_t compile_to_type(env_t *env, ast_t *ast, type_t *t) {
if (ast->tag == Integer && is_numeric_type(non_optional(t))) {
return compile_int_to_type(env, ast, t);
+ } else if (ast->tag == Number && t->tag == RealType) {
+ return compile(env, ast);
} else if (ast->tag == Number && t->tag == FloatType) {
- double n = Match(ast, Number)->n;
+ Real_t real = Match(ast, Number)->n;
+ double n = Real$as_float64(real, true);
switch (Match(t, FloatType)->bits) {
case TYPE_NBITS64: return Text$from_str(String(hex_double(n)));
case TYPE_NBITS32: return Text$from_str(String(hex_double(n), "f"));