Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
authorWuzzy <Wuzzy2@mail.ru>
Fri, 09 Nov 2018 16:28:23 +0100
changeset 14206 801dc57371c3
parent 14205 ab77b144245d
child 14207 0d18ecb520ed
Pas2C: Fix bad C typedefs for Pascal data types Extended and Real
project_files/hwc/rtl/pas2c.h
project_files/hwc/rtl/pmath.c
project_files/hwc/rtl/pmath.h
project_files/hwc/rtl/tests/check_system.c
--- a/project_files/hwc/rtl/pas2c.h	Fri Nov 09 17:44:19 2018 +0300
+++ b/project_files/hwc/rtl/pas2c.h	Fri Nov 09 16:28:23 2018 +0100
@@ -49,8 +49,8 @@
 typedef LongWord Cardinal;
 
 typedef LongInt Integer;
-typedef float extended;
-typedef float real;
+typedef long double extended;
+typedef double real;
 typedef float single;
 
 typedef bool boolean;
--- a/project_files/hwc/rtl/pmath.c	Fri Nov 09 17:44:19 2018 +0300
+++ b/project_files/hwc/rtl/pmath.c	Fri Nov 09 16:28:23 2018 +0100
@@ -32,12 +32,16 @@
 
 float __attribute__((overloadable)) fpcrtl_abs(float x)
 {
-    return fabs(x);
+    return fabsf(x);
 }
 double __attribute__((overloadable)) fpcrtl_abs(double x)
 {
     return fabs(x);
 }
+long double __attribute__((overloadable)) fpcrtl_abs(long double x)
+{
+    return fabsl(x);
+}
 int __attribute__((overloadable)) fpcrtl_abs(int x)
 {
     return abs(x);
--- a/project_files/hwc/rtl/pmath.h	Fri Nov 09 17:44:19 2018 +0300
+++ b/project_files/hwc/rtl/pmath.h	Fri Nov 09 16:28:23 2018 +0100
@@ -18,6 +18,7 @@
 
 float       __attribute__((overloadable))   fpcrtl_abs(float x);
 double      __attribute__((overloadable))   fpcrtl_abs(double x);
+long double __attribute__((overloadable))   fpcrtl_abs(long double x);
 int         __attribute__((overloadable))   fpcrtl_abs(int x);
 int64_t     __attribute__((overloadable))   fpcrtl_abs(int64_t x);
 
@@ -28,6 +29,8 @@
 double      sin(double);
 double      cos(double);
 double      fabs(double);
+float       fabsf(float);
+long double fabsl(long double);
 double      ceil(double);
 double      sqrt(double);
 double      atan(double);
--- a/project_files/hwc/rtl/tests/check_system.c	Fri Nov 09 17:44:19 2018 +0300
+++ b/project_files/hwc/rtl/tests/check_system.c	Fri Nov 09 16:28:23 2018 +0100
@@ -130,6 +130,24 @@
           fail_unless(fpcrtl_trunc(-123.456) == -123, "trunc(-123.456)");
           fail_unless(fpcrtl_trunc(12.3456) == 12, "trunc(12.3456)");
           fail_unless(fpcrtl_trunc(-12.3456) == -12, "trunc(-12.3456)");
+          fail_unless(fpcrtl_trunc(0.3) == 0, "trunc(0.3)");
+          fail_unless(fpcrtl_trunc(0.5) == 0, "trunc(0.5)");
+          fail_unless(fpcrtl_trunc(99.9999999) == 99, "trunc(99.9999999)");
+          fail_unless(fpcrtl_trunc(0x01000000.0) == 0x01000000, "trunc(0x01000000.0)");
+          fail_unless(fpcrtl_trunc(0x01000001.0) == 0x01000001, "trunc(0x01000001.0)");
+          fail_unless(fpcrtl_trunc(0x02000000.0) == 0x02000000, "trunc(0x02000000.0)");
+          fail_unless(fpcrtl_trunc(0x04000000.0) == 0x04000000, "trunc(0x04000000.0)");
+          fail_unless(fpcrtl_trunc(0x08000000.0) == 0x08000000, "trunc(0x08000000.0)");
+          fail_unless(fpcrtl_trunc(0x10000000.0) == 0x10000000, "trunc(0x10000000.0)");
+          fail_unless(fpcrtl_trunc(0x10000001.0) == 0x10000001, "trunc(0x10000001.0)");
+          fail_unless(fpcrtl_trunc(0x20000000.0) == 0x20000000, "trunc(0x20000000.0)");
+          fail_unless(fpcrtl_trunc(0x40000000.0) == 0x40000000, "trunc(0x40000000.0)");
+          fail_unless(fpcrtl_trunc(0x80000000.0) == 0x80000000, "trunc(0x80000000.0)");
+          fail_unless(fpcrtl_trunc(0xF0000000.0) == 0xF0000000, "trunc(0xF0000000.0)");
+          fail_unless(fpcrtl_trunc(0xF0000001.0) == 0xF0000001, "trunc(0xF0000001.0)");
+          fail_unless(fpcrtl_trunc(0x01010101.0) == 0x01010101, "trunc(0x01010101.0)");
+          fail_unless(fpcrtl_trunc(0xFFFFFFFF.0) == 0xFFFFFFFF, "trunc(0xFFFFFFFF.0)");
+          fail_unless(fpcrtl_trunc(0x8943FE39.0) == 0x8943FE39, "trunc(0x01000000.0)");
     }
 END_TEST