lib/iec_std_lib.h
changeset 314 41d4ac0b4821
parent 313 90c3772e6547
child 348 990ecb883731
child 350 2c3c4dc34979
--- a/lib/iec_std_lib.h	Mon Jun 06 14:05:28 2011 +0100
+++ b/lib/iec_std_lib.h	Mon Jun 06 16:28:41 2011 +0200
@@ -471,6 +471,33 @@
 /***************/
 /* Convertions */
 /***************/
+    /*****************/
+    /*  REAL_TO_INT  */
+    /*****************/
+static inline LINT __real_round(LREAL IN)
+{
+	return fmod(IN, 1) == 0 ? ((LINT)IN / 2) * 2 : (LINT)IN;
+}
+static inline LINT __preal_to_sint(LREAL IN)
+{
+   return IN >= 0 ? __real_round(IN + 0.5) : __real_round(IN - 0.5);
+}
+static inline LINT __preal_to_uint(LREAL IN)
+{
+   return IN >= 0 ? __real_round(IN + 0.5) : 0;
+}
+static inline LINT __real_to_sint(EN_ENO_PARAMS, LREAL IN){
+    TEST_EN(LINT)
+    return (LINT)__preal_to_sint(IN);
+}
+static inline LWORD __real_to_bit(EN_ENO_PARAMS, LREAL IN){
+    TEST_EN(LWORD)
+    return (LWORD)__preal_to_uint(IN);
+}
+static inline ULINT __real_to_uint(EN_ENO_PARAMS, LREAL IN){
+    TEST_EN(ULINT)
+    return (ULINT)__preal_to_uint(IN);
+}
     /***************/
     /*  TO_STRING  */
     /***************/
@@ -584,7 +611,7 @@
 
 static inline LINT __string_to_sint(EN_ENO_PARAMS, STRING IN){
     TEST_EN(LINT)
-    return (LWORD)__pstring_to_sint(&IN);
+    return (LINT)__pstring_to_sint(&IN);
 }
 static inline LWORD __string_to_bit(EN_ENO_PARAMS, STRING IN){
     TEST_EN(LWORD)