lib/iec_std_lib.h
changeset 314 41d4ac0b4821
parent 313 90c3772e6547
child 348 990ecb883731
child 350 2c3c4dc34979
equal deleted inserted replaced
313:90c3772e6547 314:41d4ac0b4821
   469 }
   469 }
   470 
   470 
   471 /***************/
   471 /***************/
   472 /* Convertions */
   472 /* Convertions */
   473 /***************/
   473 /***************/
       
   474     /*****************/
       
   475     /*  REAL_TO_INT  */
       
   476     /*****************/
       
   477 static inline LINT __real_round(LREAL IN)
       
   478 {
       
   479 	return fmod(IN, 1) == 0 ? ((LINT)IN / 2) * 2 : (LINT)IN;
       
   480 }
       
   481 static inline LINT __preal_to_sint(LREAL IN)
       
   482 {
       
   483    return IN >= 0 ? __real_round(IN + 0.5) : __real_round(IN - 0.5);
       
   484 }
       
   485 static inline LINT __preal_to_uint(LREAL IN)
       
   486 {
       
   487    return IN >= 0 ? __real_round(IN + 0.5) : 0;
       
   488 }
       
   489 static inline LINT __real_to_sint(EN_ENO_PARAMS, LREAL IN){
       
   490     TEST_EN(LINT)
       
   491     return (LINT)__preal_to_sint(IN);
       
   492 }
       
   493 static inline LWORD __real_to_bit(EN_ENO_PARAMS, LREAL IN){
       
   494     TEST_EN(LWORD)
       
   495     return (LWORD)__preal_to_uint(IN);
       
   496 }
       
   497 static inline ULINT __real_to_uint(EN_ENO_PARAMS, LREAL IN){
       
   498     TEST_EN(ULINT)
       
   499     return (ULINT)__preal_to_uint(IN);
       
   500 }
   474     /***************/
   501     /***************/
   475     /*  TO_STRING  */
   502     /*  TO_STRING  */
   476     /***************/
   503     /***************/
   477 static inline STRING __bool_to_string(EN_ENO_PARAMS, BOOL IN)
   504 static inline STRING __bool_to_string(EN_ENO_PARAMS, BOOL IN)
   478 {
   505 {
   582     return res;
   609     return res;
   583 }
   610 }
   584 
   611 
   585 static inline LINT __string_to_sint(EN_ENO_PARAMS, STRING IN){
   612 static inline LINT __string_to_sint(EN_ENO_PARAMS, STRING IN){
   586     TEST_EN(LINT)
   613     TEST_EN(LINT)
   587     return (LWORD)__pstring_to_sint(&IN);
   614     return (LINT)__pstring_to_sint(&IN);
   588 }
   615 }
   589 static inline LWORD __string_to_bit(EN_ENO_PARAMS, STRING IN){
   616 static inline LWORD __string_to_bit(EN_ENO_PARAMS, STRING IN){
   590     TEST_EN(LWORD)
   617     TEST_EN(LWORD)
   591     return (LWORD)__pstring_to_sint(&IN);
   618     return (LWORD)__pstring_to_sint(&IN);
   592 }
   619 }