1.1 --- a/templates/native/float.c Thu Nov 04 23:44:29 2021 +0100
1.2 +++ b/templates/native/float.c Thu Nov 04 23:57:33 2021 +0100
1.3 @@ -1,6 +1,6 @@
1.4 /* Native functions for floating point operations.
1.5
1.6 -Copyright (C) 2016, 2017, 2018, 2019 Paul Boddie <paul@boddie.org.uk>
1.7 +Copyright (C) 2016, 2017, 2018, 2019, 2021 Paul Boddie <paul@boddie.org.uk>
1.8
1.9 This program is free software; you can redistribute it and/or modify it under
1.10 the terms of the GNU General Public License as published by the Free Software
1.11 @@ -28,9 +28,9 @@
1.12 #include "progtypes.h"
1.13 #include "main.h"
1.14
1.15 -/* Conversion of trailing data to a double-precision floating point number. */
1.16 +/* Conversion of trailing data to a floating point number. */
1.17
1.18 -static double __TOFLOAT(__attr attr)
1.19 +static __float __TOFLOAT(__attr attr)
1.20 {
1.21 return __get_trailing_data(attr, __builtins___float_float);
1.22 }
1.23 @@ -38,7 +38,7 @@
1.24 /* Numeric formatting using snprintf.
1.25 NOTE: This might be moved elsewhere and used by other types. */
1.26
1.27 -static __attr format_number(double n, int size)
1.28 +static __attr format_number(__float n, int size)
1.29 {
1.30 char *s = (char *) __ALLOCATE(size, sizeof(char));
1.31 int digits;
1.32 @@ -48,7 +48,7 @@
1.33
1.34 while (1)
1.35 {
1.36 - digits = snprintf(s, size, "%f", n);
1.37 + digits = snprintf(s, size, "%f", (double) n);
1.38
1.39 if (digits < size)
1.40 {
1.41 @@ -68,56 +68,56 @@
1.42 __attr __fn_native_float_float_add(__attr __self, __attr self, __attr other)
1.43 {
1.44 /* self and other interpreted as float */
1.45 - double i = __TOFLOAT(self);
1.46 - double j = __TOFLOAT(other);
1.47 + __float i = __TOFLOAT(self);
1.48 + __float j = __TOFLOAT(other);
1.49 return __new_float(i + j);
1.50 }
1.51
1.52 __attr __fn_native_float_float_sub(__attr __self, __attr self, __attr other)
1.53 {
1.54 /* self and other interpreted as float */
1.55 - double i = __TOFLOAT(self);
1.56 - double j = __TOFLOAT(other);
1.57 + __float i = __TOFLOAT(self);
1.58 + __float j = __TOFLOAT(other);
1.59 return __new_float(i - j);
1.60 }
1.61
1.62 __attr __fn_native_float_float_mul(__attr __self, __attr self, __attr other)
1.63 {
1.64 /* self and other interpreted as float */
1.65 - double i = __TOFLOAT(self);
1.66 - double j = __TOFLOAT(other);
1.67 + __float i = __TOFLOAT(self);
1.68 + __float j = __TOFLOAT(other);
1.69 return __new_float(i * j);
1.70 }
1.71
1.72 __attr __fn_native_float_float_div(__attr __self, __attr self, __attr other)
1.73 {
1.74 /* self and other interpreted as float */
1.75 - double i = __TOFLOAT(self);
1.76 - double j = __TOFLOAT(other);
1.77 + __float i = __TOFLOAT(self);
1.78 + __float j = __TOFLOAT(other);
1.79 return __new_float(i / j);
1.80 }
1.81
1.82 __attr __fn_native_float_float_mod(__attr __self, __attr self, __attr other)
1.83 {
1.84 /* self and other interpreted as float */
1.85 - double i = __TOFLOAT(self);
1.86 - double j = __TOFLOAT(other);
1.87 + __float i = __TOFLOAT(self);
1.88 + __float j = __TOFLOAT(other);
1.89 return __new_float(fmod(i, j));
1.90 }
1.91
1.92 __attr __fn_native_float_float_neg(__attr __self, __attr self)
1.93 {
1.94 /* self interpreted as float */
1.95 - double i = __TOFLOAT(self);
1.96 + __float i = __TOFLOAT(self);
1.97 return __new_float(-i);
1.98 }
1.99
1.100 __attr __fn_native_float_float_pow(__attr __self, __attr self, __attr other)
1.101 {
1.102 /* self and other interpreted as float */
1.103 - double i = __TOFLOAT(self);
1.104 - double j = __TOFLOAT(other);
1.105 - double result;
1.106 + __float i = __TOFLOAT(self);
1.107 + __float j = __TOFLOAT(other);
1.108 + __float result;
1.109
1.110 errno = 0;
1.111 result = pow(i, j);
1.112 @@ -134,8 +134,8 @@
1.113 __attr __fn_native_float_float_le(__attr __self, __attr self, __attr other)
1.114 {
1.115 /* self and other interpreted as float */
1.116 - double i = __TOFLOAT(self);
1.117 - double j = __TOFLOAT(other);
1.118 + __float i = __TOFLOAT(self);
1.119 + __float j = __TOFLOAT(other);
1.120
1.121 /* Return a boolean result. */
1.122 return i <= j ? __builtins___boolean_True : __builtins___boolean_False;
1.123 @@ -144,8 +144,8 @@
1.124 __attr __fn_native_float_float_lt(__attr __self, __attr self, __attr other)
1.125 {
1.126 /* self and other interpreted as float */
1.127 - double i = __TOFLOAT(self);
1.128 - double j = __TOFLOAT(other);
1.129 + __float i = __TOFLOAT(self);
1.130 + __float j = __TOFLOAT(other);
1.131
1.132 /* Return a boolean result. */
1.133 return i < j ? __builtins___boolean_True : __builtins___boolean_False;
1.134 @@ -154,8 +154,8 @@
1.135 __attr __fn_native_float_float_ge(__attr __self, __attr self, __attr other)
1.136 {
1.137 /* self and other interpreted as float */
1.138 - double i = __TOFLOAT(self);
1.139 - double j = __TOFLOAT(other);
1.140 + __float i = __TOFLOAT(self);
1.141 + __float j = __TOFLOAT(other);
1.142
1.143 /* Return a boolean result. */
1.144 return i >= j ? __builtins___boolean_True : __builtins___boolean_False;
1.145 @@ -164,8 +164,8 @@
1.146 __attr __fn_native_float_float_gt(__attr __self, __attr self, __attr other)
1.147 {
1.148 /* self and other interpreted as float */
1.149 - double i = __TOFLOAT(self);
1.150 - double j = __TOFLOAT(other);
1.151 + __float i = __TOFLOAT(self);
1.152 + __float j = __TOFLOAT(other);
1.153
1.154 /* Return a boolean result. */
1.155 return i > j ? __builtins___boolean_True : __builtins___boolean_False;
1.156 @@ -174,8 +174,8 @@
1.157 __attr __fn_native_float_float_eq(__attr __self, __attr self, __attr other)
1.158 {
1.159 /* self and other interpreted as float */
1.160 - double i = __TOFLOAT(self);
1.161 - double j = __TOFLOAT(other);
1.162 + __float i = __TOFLOAT(self);
1.163 + __float j = __TOFLOAT(other);
1.164
1.165 /* Return a boolean result. */
1.166 return i == j ? __builtins___boolean_True : __builtins___boolean_False;
1.167 @@ -184,8 +184,8 @@
1.168 __attr __fn_native_float_float_ne(__attr __self, __attr self, __attr other)
1.169 {
1.170 /* self and other interpreted as float */
1.171 - double i = __TOFLOAT(self);
1.172 - double j = __TOFLOAT(other);
1.173 + __float i = __TOFLOAT(self);
1.174 + __float j = __TOFLOAT(other);
1.175
1.176 /* Return a boolean result. */
1.177 return i != j ? __builtins___boolean_True : __builtins___boolean_False;
1.178 @@ -194,7 +194,7 @@
1.179 __attr __fn_native_float_float_str(__attr __self, __attr self)
1.180 {
1.181 /* self interpreted as float */
1.182 - double i = __TOFLOAT(self);
1.183 + __float i = __TOFLOAT(self);
1.184
1.185 /* Return a new string. */
1.186 return format_number(i, 64);
1.187 @@ -203,7 +203,7 @@
1.188 __attr __fn_native_float_float_int(__attr __self, __attr self)
1.189 {
1.190 /* self interpreted as float */
1.191 - double i = __TOFLOAT(self);
1.192 + __float i = __TOFLOAT(self);
1.193
1.194 /* NOTE: Test for conversion failure. */
1.195 return __new_int((int) i);