diff --git a/libs/stdlib/iec61131-st/to_num.py b/libs/stdlib/iec61131-st/to_num.py new file mode 100644 index 0000000000..28b8cee64b --- /dev/null +++ b/libs/stdlib/iec61131-st/to_num.py @@ -0,0 +1,87 @@ +f = open("to_num.st", "w") + +types = [ + "SINT", + "USINT", + "INT", + "UINT", + "DINT", + "UDINT", + "LINT", + "ULINT", + + "REAL", + "LREAL", + + # "BIT", + # "BOOL", + # "BYTE", + # "WORD", + # "DWORD", + # "LWORD", + + # "STRING", + # "WSTRING", + + # "TIME", + # "LTIME", + # "DATE", + # "LDATE", + # "DT", + # "LDT", + # "TOD", + # "LTOD", +] + +generic = """(******************** +* +* Converts any other numerical value to {0} +* +*********************) +FUNCTION TO_{0} : {0} + VAR_INPUT + in : T; + END_VAR +END_FUNCTION +""" + +generic_impl = """(******************** +* +* Converts {0} to {1} +* +*********************) +FUNCTION TO_{1}__{0} : {1} + VAR_INPUT + in : {0}; + END_VAR + + TO_{1}__{0} := {0}_TO_{1}(in); +END_FUNCTION +""" + +generic_impl_same = """(******************** +* +* Converts {0} to {1} +* +*********************) +FUNCTION TO_{1}__{0} : {1} + VAR_INPUT + in : {0}; + END_VAR + + TO_{1}__{0} := in; +END_FUNCTION +""" + +for type_from in types: + f.write(generic.format(type_from)) + f.write("\n") + + for type_to in types: + if type_from == type_to: + f.write(generic_impl_same.format(type_from, type_to)) + else: + f.write(generic_impl.format(type_from, type_to)) + + f.write("\n") + diff --git a/libs/stdlib/iec61131-st/to_num.st b/libs/stdlib/iec61131-st/to_num.st new file mode 100644 index 0000000000..fcb60a6616 --- /dev/null +++ b/libs/stdlib/iec61131-st/to_num.st @@ -0,0 +1,1410 @@ +(******************** +* +* Converts any other numerical value to SINT +* +*********************) +FUNCTION TO_SINT : SINT + VAR_INPUT + in : T; + END_VAR +END_FUNCTION + +(******************** +* +* Converts SINT to SINT +* +*********************) +FUNCTION TO_SINT__SINT : SINT + VAR_INPUT + in : SINT; + END_VAR + + TO_SINT__SINT := in; +END_FUNCTION + +(******************** +* +* Converts SINT to USINT +* +*********************) +FUNCTION TO_USINT__SINT : USINT + VAR_INPUT + in : SINT; + END_VAR + + TO_USINT__SINT := SINT_TO_USINT(in); +END_FUNCTION + +(******************** +* +* Converts SINT to INT +* +*********************) +FUNCTION TO_INT__SINT : INT + VAR_INPUT + in : SINT; + END_VAR + + TO_INT__SINT := SINT_TO_INT(in); +END_FUNCTION + +(******************** +* +* Converts SINT to UINT +* +*********************) +FUNCTION TO_UINT__SINT : UINT + VAR_INPUT + in : SINT; + END_VAR + + TO_UINT__SINT := SINT_TO_UINT(in); +END_FUNCTION + +(******************** +* +* Converts SINT to DINT +* +*********************) +FUNCTION TO_DINT__SINT : DINT + VAR_INPUT + in : SINT; + END_VAR + + TO_DINT__SINT := SINT_TO_DINT(in); +END_FUNCTION + +(******************** +* +* Converts SINT to UDINT +* +*********************) +FUNCTION TO_UDINT__SINT : UDINT + VAR_INPUT + in : SINT; + END_VAR + + TO_UDINT__SINT := SINT_TO_UDINT(in); +END_FUNCTION + +(******************** +* +* Converts SINT to LINT +* +*********************) +FUNCTION TO_LINT__SINT : LINT + VAR_INPUT + in : SINT; + END_VAR + + TO_LINT__SINT := SINT_TO_LINT(in); +END_FUNCTION + +(******************** +* +* Converts SINT to ULINT +* +*********************) +FUNCTION TO_ULINT__SINT : ULINT + VAR_INPUT + in : SINT; + END_VAR + + TO_ULINT__SINT := SINT_TO_ULINT(in); +END_FUNCTION + +(******************** +* +* Converts SINT to REAL +* +*********************) +FUNCTION TO_REAL__SINT : REAL + VAR_INPUT + in : SINT; + END_VAR + + TO_REAL__SINT := SINT_TO_REAL(in); +END_FUNCTION + +(******************** +* +* Converts SINT to LREAL +* +*********************) +FUNCTION TO_LREAL__SINT : LREAL + VAR_INPUT + in : SINT; + END_VAR + + TO_LREAL__SINT := SINT_TO_LREAL(in); +END_FUNCTION + +(******************** +* +* Converts any other numerical value to USINT +* +*********************) +FUNCTION TO_USINT : USINT + VAR_INPUT + in : T; + END_VAR +END_FUNCTION + +(******************** +* +* Converts USINT to SINT +* +*********************) +FUNCTION TO_SINT__USINT : SINT + VAR_INPUT + in : USINT; + END_VAR + + TO_SINT__USINT := USINT_TO_SINT(in); +END_FUNCTION + +(******************** +* +* Converts USINT to USINT +* +*********************) +FUNCTION TO_USINT__USINT : USINT + VAR_INPUT + in : USINT; + END_VAR + + TO_USINT__USINT := in; +END_FUNCTION + +(******************** +* +* Converts USINT to INT +* +*********************) +FUNCTION TO_INT__USINT : INT + VAR_INPUT + in : USINT; + END_VAR + + TO_INT__USINT := USINT_TO_INT(in); +END_FUNCTION + +(******************** +* +* Converts USINT to UINT +* +*********************) +FUNCTION TO_UINT__USINT : UINT + VAR_INPUT + in : USINT; + END_VAR + + TO_UINT__USINT := USINT_TO_UINT(in); +END_FUNCTION + +(******************** +* +* Converts USINT to DINT +* +*********************) +FUNCTION TO_DINT__USINT : DINT + VAR_INPUT + in : USINT; + END_VAR + + TO_DINT__USINT := USINT_TO_DINT(in); +END_FUNCTION + +(******************** +* +* Converts USINT to UDINT +* +*********************) +FUNCTION TO_UDINT__USINT : UDINT + VAR_INPUT + in : USINT; + END_VAR + + TO_UDINT__USINT := USINT_TO_UDINT(in); +END_FUNCTION + +(******************** +* +* Converts USINT to LINT +* +*********************) +FUNCTION TO_LINT__USINT : LINT + VAR_INPUT + in : USINT; + END_VAR + + TO_LINT__USINT := USINT_TO_LINT(in); +END_FUNCTION + +(******************** +* +* Converts USINT to ULINT +* +*********************) +FUNCTION TO_ULINT__USINT : ULINT + VAR_INPUT + in : USINT; + END_VAR + + TO_ULINT__USINT := USINT_TO_ULINT(in); +END_FUNCTION + +(******************** +* +* Converts USINT to REAL +* +*********************) +FUNCTION TO_REAL__USINT : REAL + VAR_INPUT + in : USINT; + END_VAR + + TO_REAL__USINT := USINT_TO_REAL(in); +END_FUNCTION + +(******************** +* +* Converts USINT to LREAL +* +*********************) +FUNCTION TO_LREAL__USINT : LREAL + VAR_INPUT + in : USINT; + END_VAR + + TO_LREAL__USINT := USINT_TO_LREAL(in); +END_FUNCTION + +(******************** +* +* Converts any other numerical value to INT +* +*********************) +FUNCTION TO_INT : INT + VAR_INPUT + in : T; + END_VAR +END_FUNCTION + +(******************** +* +* Converts INT to SINT +* +*********************) +FUNCTION TO_SINT__INT : SINT + VAR_INPUT + in : INT; + END_VAR + + TO_SINT__INT := INT_TO_SINT(in); +END_FUNCTION + +(******************** +* +* Converts INT to USINT +* +*********************) +FUNCTION TO_USINT__INT : USINT + VAR_INPUT + in : INT; + END_VAR + + TO_USINT__INT := INT_TO_USINT(in); +END_FUNCTION + +(******************** +* +* Converts INT to INT +* +*********************) +FUNCTION TO_INT__INT : INT + VAR_INPUT + in : INT; + END_VAR + + TO_INT__INT := in; +END_FUNCTION + +(******************** +* +* Converts INT to UINT +* +*********************) +FUNCTION TO_UINT__INT : UINT + VAR_INPUT + in : INT; + END_VAR + + TO_UINT__INT := INT_TO_UINT(in); +END_FUNCTION + +(******************** +* +* Converts INT to DINT +* +*********************) +FUNCTION TO_DINT__INT : DINT + VAR_INPUT + in : INT; + END_VAR + + TO_DINT__INT := INT_TO_DINT(in); +END_FUNCTION + +(******************** +* +* Converts INT to UDINT +* +*********************) +FUNCTION TO_UDINT__INT : UDINT + VAR_INPUT + in : INT; + END_VAR + + TO_UDINT__INT := INT_TO_UDINT(in); +END_FUNCTION + +(******************** +* +* Converts INT to LINT +* +*********************) +FUNCTION TO_LINT__INT : LINT + VAR_INPUT + in : INT; + END_VAR + + TO_LINT__INT := INT_TO_LINT(in); +END_FUNCTION + +(******************** +* +* Converts INT to ULINT +* +*********************) +FUNCTION TO_ULINT__INT : ULINT + VAR_INPUT + in : INT; + END_VAR + + TO_ULINT__INT := INT_TO_ULINT(in); +END_FUNCTION + +(******************** +* +* Converts INT to REAL +* +*********************) +FUNCTION TO_REAL__INT : REAL + VAR_INPUT + in : INT; + END_VAR + + TO_REAL__INT := INT_TO_REAL(in); +END_FUNCTION + +(******************** +* +* Converts INT to LREAL +* +*********************) +FUNCTION TO_LREAL__INT : LREAL + VAR_INPUT + in : INT; + END_VAR + + TO_LREAL__INT := INT_TO_LREAL(in); +END_FUNCTION + +(******************** +* +* Converts any other numerical value to UINT +* +*********************) +FUNCTION TO_UINT : UINT + VAR_INPUT + in : T; + END_VAR +END_FUNCTION + +(******************** +* +* Converts UINT to SINT +* +*********************) +FUNCTION TO_SINT__UINT : SINT + VAR_INPUT + in : UINT; + END_VAR + + TO_SINT__UINT := UINT_TO_SINT(in); +END_FUNCTION + +(******************** +* +* Converts UINT to USINT +* +*********************) +FUNCTION TO_USINT__UINT : USINT + VAR_INPUT + in : UINT; + END_VAR + + TO_USINT__UINT := UINT_TO_USINT(in); +END_FUNCTION + +(******************** +* +* Converts UINT to INT +* +*********************) +FUNCTION TO_INT__UINT : INT + VAR_INPUT + in : UINT; + END_VAR + + TO_INT__UINT := UINT_TO_INT(in); +END_FUNCTION + +(******************** +* +* Converts UINT to UINT +* +*********************) +FUNCTION TO_UINT__UINT : UINT + VAR_INPUT + in : UINT; + END_VAR + + TO_UINT__UINT := in; +END_FUNCTION + +(******************** +* +* Converts UINT to DINT +* +*********************) +FUNCTION TO_DINT__UINT : DINT + VAR_INPUT + in : UINT; + END_VAR + + TO_DINT__UINT := UINT_TO_DINT(in); +END_FUNCTION + +(******************** +* +* Converts UINT to UDINT +* +*********************) +FUNCTION TO_UDINT__UINT : UDINT + VAR_INPUT + in : UINT; + END_VAR + + TO_UDINT__UINT := UINT_TO_UDINT(in); +END_FUNCTION + +(******************** +* +* Converts UINT to LINT +* +*********************) +FUNCTION TO_LINT__UINT : LINT + VAR_INPUT + in : UINT; + END_VAR + + TO_LINT__UINT := UINT_TO_LINT(in); +END_FUNCTION + +(******************** +* +* Converts UINT to ULINT +* +*********************) +FUNCTION TO_ULINT__UINT : ULINT + VAR_INPUT + in : UINT; + END_VAR + + TO_ULINT__UINT := UINT_TO_ULINT(in); +END_FUNCTION + +(******************** +* +* Converts UINT to REAL +* +*********************) +FUNCTION TO_REAL__UINT : REAL + VAR_INPUT + in : UINT; + END_VAR + + TO_REAL__UINT := UINT_TO_REAL(in); +END_FUNCTION + +(******************** +* +* Converts UINT to LREAL +* +*********************) +FUNCTION TO_LREAL__UINT : LREAL + VAR_INPUT + in : UINT; + END_VAR + + TO_LREAL__UINT := UINT_TO_LREAL(in); +END_FUNCTION + +(******************** +* +* Converts any other numerical value to DINT +* +*********************) +FUNCTION TO_DINT : DINT + VAR_INPUT + in : T; + END_VAR +END_FUNCTION + +(******************** +* +* Converts DINT to SINT +* +*********************) +FUNCTION TO_SINT__DINT : SINT + VAR_INPUT + in : DINT; + END_VAR + + TO_SINT__DINT := DINT_TO_SINT(in); +END_FUNCTION + +(******************** +* +* Converts DINT to USINT +* +*********************) +FUNCTION TO_USINT__DINT : USINT + VAR_INPUT + in : DINT; + END_VAR + + TO_USINT__DINT := DINT_TO_USINT(in); +END_FUNCTION + +(******************** +* +* Converts DINT to INT +* +*********************) +FUNCTION TO_INT__DINT : INT + VAR_INPUT + in : DINT; + END_VAR + + TO_INT__DINT := DINT_TO_INT(in); +END_FUNCTION + +(******************** +* +* Converts DINT to UINT +* +*********************) +FUNCTION TO_UINT__DINT : UINT + VAR_INPUT + in : DINT; + END_VAR + + TO_UINT__DINT := DINT_TO_UINT(in); +END_FUNCTION + +(******************** +* +* Converts DINT to DINT +* +*********************) +FUNCTION TO_DINT__DINT : DINT + VAR_INPUT + in : DINT; + END_VAR + + TO_DINT__DINT := in; +END_FUNCTION + +(******************** +* +* Converts DINT to UDINT +* +*********************) +FUNCTION TO_UDINT__DINT : UDINT + VAR_INPUT + in : DINT; + END_VAR + + TO_UDINT__DINT := DINT_TO_UDINT(in); +END_FUNCTION + +(******************** +* +* Converts DINT to LINT +* +*********************) +FUNCTION TO_LINT__DINT : LINT + VAR_INPUT + in : DINT; + END_VAR + + TO_LINT__DINT := DINT_TO_LINT(in); +END_FUNCTION + +(******************** +* +* Converts DINT to ULINT +* +*********************) +FUNCTION TO_ULINT__DINT : ULINT + VAR_INPUT + in : DINT; + END_VAR + + TO_ULINT__DINT := DINT_TO_ULINT(in); +END_FUNCTION + +(******************** +* +* Converts DINT to REAL +* +*********************) +FUNCTION TO_REAL__DINT : REAL + VAR_INPUT + in : DINT; + END_VAR + + TO_REAL__DINT := DINT_TO_REAL(in); +END_FUNCTION + +(******************** +* +* Converts DINT to LREAL +* +*********************) +FUNCTION TO_LREAL__DINT : LREAL + VAR_INPUT + in : DINT; + END_VAR + + TO_LREAL__DINT := DINT_TO_LREAL(in); +END_FUNCTION + +(******************** +* +* Converts any other numerical value to UDINT +* +*********************) +FUNCTION TO_UDINT : UDINT + VAR_INPUT + in : T; + END_VAR +END_FUNCTION + +(******************** +* +* Converts UDINT to SINT +* +*********************) +FUNCTION TO_SINT__UDINT : SINT + VAR_INPUT + in : UDINT; + END_VAR + + TO_SINT__UDINT := UDINT_TO_SINT(in); +END_FUNCTION + +(******************** +* +* Converts UDINT to USINT +* +*********************) +FUNCTION TO_USINT__UDINT : USINT + VAR_INPUT + in : UDINT; + END_VAR + + TO_USINT__UDINT := UDINT_TO_USINT(in); +END_FUNCTION + +(******************** +* +* Converts UDINT to INT +* +*********************) +FUNCTION TO_INT__UDINT : INT + VAR_INPUT + in : UDINT; + END_VAR + + TO_INT__UDINT := UDINT_TO_INT(in); +END_FUNCTION + +(******************** +* +* Converts UDINT to UINT +* +*********************) +FUNCTION TO_UINT__UDINT : UINT + VAR_INPUT + in : UDINT; + END_VAR + + TO_UINT__UDINT := UDINT_TO_UINT(in); +END_FUNCTION + +(******************** +* +* Converts UDINT to DINT +* +*********************) +FUNCTION TO_DINT__UDINT : DINT + VAR_INPUT + in : UDINT; + END_VAR + + TO_DINT__UDINT := UDINT_TO_DINT(in); +END_FUNCTION + +(******************** +* +* Converts UDINT to UDINT +* +*********************) +FUNCTION TO_UDINT__UDINT : UDINT + VAR_INPUT + in : UDINT; + END_VAR + + TO_UDINT__UDINT := in; +END_FUNCTION + +(******************** +* +* Converts UDINT to LINT +* +*********************) +FUNCTION TO_LINT__UDINT : LINT + VAR_INPUT + in : UDINT; + END_VAR + + TO_LINT__UDINT := UDINT_TO_LINT(in); +END_FUNCTION + +(******************** +* +* Converts UDINT to ULINT +* +*********************) +FUNCTION TO_ULINT__UDINT : ULINT + VAR_INPUT + in : UDINT; + END_VAR + + TO_ULINT__UDINT := UDINT_TO_ULINT(in); +END_FUNCTION + +(******************** +* +* Converts UDINT to REAL +* +*********************) +FUNCTION TO_REAL__UDINT : REAL + VAR_INPUT + in : UDINT; + END_VAR + + TO_REAL__UDINT := UDINT_TO_REAL(in); +END_FUNCTION + +(******************** +* +* Converts UDINT to LREAL +* +*********************) +FUNCTION TO_LREAL__UDINT : LREAL + VAR_INPUT + in : UDINT; + END_VAR + + TO_LREAL__UDINT := UDINT_TO_LREAL(in); +END_FUNCTION + +(******************** +* +* Converts any other numerical value to LINT +* +*********************) +FUNCTION TO_LINT : LINT + VAR_INPUT + in : T; + END_VAR +END_FUNCTION + +(******************** +* +* Converts LINT to SINT +* +*********************) +FUNCTION TO_SINT__LINT : SINT + VAR_INPUT + in : LINT; + END_VAR + + TO_SINT__LINT := LINT_TO_SINT(in); +END_FUNCTION + +(******************** +* +* Converts LINT to USINT +* +*********************) +FUNCTION TO_USINT__LINT : USINT + VAR_INPUT + in : LINT; + END_VAR + + TO_USINT__LINT := LINT_TO_USINT(in); +END_FUNCTION + +(******************** +* +* Converts LINT to INT +* +*********************) +FUNCTION TO_INT__LINT : INT + VAR_INPUT + in : LINT; + END_VAR + + TO_INT__LINT := LINT_TO_INT(in); +END_FUNCTION + +(******************** +* +* Converts LINT to UINT +* +*********************) +FUNCTION TO_UINT__LINT : UINT + VAR_INPUT + in : LINT; + END_VAR + + TO_UINT__LINT := LINT_TO_UINT(in); +END_FUNCTION + +(******************** +* +* Converts LINT to DINT +* +*********************) +FUNCTION TO_DINT__LINT : DINT + VAR_INPUT + in : LINT; + END_VAR + + TO_DINT__LINT := LINT_TO_DINT(in); +END_FUNCTION + +(******************** +* +* Converts LINT to UDINT +* +*********************) +FUNCTION TO_UDINT__LINT : UDINT + VAR_INPUT + in : LINT; + END_VAR + + TO_UDINT__LINT := LINT_TO_UDINT(in); +END_FUNCTION + +(******************** +* +* Converts LINT to LINT +* +*********************) +FUNCTION TO_LINT__LINT : LINT + VAR_INPUT + in : LINT; + END_VAR + + TO_LINT__LINT := in; +END_FUNCTION + +(******************** +* +* Converts LINT to ULINT +* +*********************) +FUNCTION TO_ULINT__LINT : ULINT + VAR_INPUT + in : LINT; + END_VAR + + TO_ULINT__LINT := LINT_TO_ULINT(in); +END_FUNCTION + +(******************** +* +* Converts LINT to REAL +* +*********************) +FUNCTION TO_REAL__LINT : REAL + VAR_INPUT + in : LINT; + END_VAR + + TO_REAL__LINT := LINT_TO_REAL(in); +END_FUNCTION + +(******************** +* +* Converts LINT to LREAL +* +*********************) +FUNCTION TO_LREAL__LINT : LREAL + VAR_INPUT + in : LINT; + END_VAR + + TO_LREAL__LINT := LINT_TO_LREAL(in); +END_FUNCTION + +(******************** +* +* Converts any other numerical value to ULINT +* +*********************) +FUNCTION TO_ULINT : ULINT + VAR_INPUT + in : T; + END_VAR +END_FUNCTION + +(******************** +* +* Converts ULINT to SINT +* +*********************) +FUNCTION TO_SINT__ULINT : SINT + VAR_INPUT + in : ULINT; + END_VAR + + TO_SINT__ULINT := ULINT_TO_SINT(in); +END_FUNCTION + +(******************** +* +* Converts ULINT to USINT +* +*********************) +FUNCTION TO_USINT__ULINT : USINT + VAR_INPUT + in : ULINT; + END_VAR + + TO_USINT__ULINT := ULINT_TO_USINT(in); +END_FUNCTION + +(******************** +* +* Converts ULINT to INT +* +*********************) +FUNCTION TO_INT__ULINT : INT + VAR_INPUT + in : ULINT; + END_VAR + + TO_INT__ULINT := ULINT_TO_INT(in); +END_FUNCTION + +(******************** +* +* Converts ULINT to UINT +* +*********************) +FUNCTION TO_UINT__ULINT : UINT + VAR_INPUT + in : ULINT; + END_VAR + + TO_UINT__ULINT := ULINT_TO_UINT(in); +END_FUNCTION + +(******************** +* +* Converts ULINT to DINT +* +*********************) +FUNCTION TO_DINT__ULINT : DINT + VAR_INPUT + in : ULINT; + END_VAR + + TO_DINT__ULINT := ULINT_TO_DINT(in); +END_FUNCTION + +(******************** +* +* Converts ULINT to UDINT +* +*********************) +FUNCTION TO_UDINT__ULINT : UDINT + VAR_INPUT + in : ULINT; + END_VAR + + TO_UDINT__ULINT := ULINT_TO_UDINT(in); +END_FUNCTION + +(******************** +* +* Converts ULINT to LINT +* +*********************) +FUNCTION TO_LINT__ULINT : LINT + VAR_INPUT + in : ULINT; + END_VAR + + TO_LINT__ULINT := ULINT_TO_LINT(in); +END_FUNCTION + +(******************** +* +* Converts ULINT to ULINT +* +*********************) +FUNCTION TO_ULINT__ULINT : ULINT + VAR_INPUT + in : ULINT; + END_VAR + + TO_ULINT__ULINT := in; +END_FUNCTION + +(******************** +* +* Converts ULINT to REAL +* +*********************) +FUNCTION TO_REAL__ULINT : REAL + VAR_INPUT + in : ULINT; + END_VAR + + TO_REAL__ULINT := ULINT_TO_REAL(in); +END_FUNCTION + +(******************** +* +* Converts ULINT to LREAL +* +*********************) +FUNCTION TO_LREAL__ULINT : LREAL + VAR_INPUT + in : ULINT; + END_VAR + + TO_LREAL__ULINT := ULINT_TO_LREAL(in); +END_FUNCTION + +(******************** +* +* Converts any other numerical value to REAL +* +*********************) +FUNCTION TO_REAL : REAL + VAR_INPUT + in : T; + END_VAR +END_FUNCTION + +(******************** +* +* Converts REAL to SINT +* +*********************) +FUNCTION TO_SINT__REAL : SINT + VAR_INPUT + in : REAL; + END_VAR + + TO_SINT__REAL := REAL_TO_SINT(in); +END_FUNCTION + +(******************** +* +* Converts REAL to USINT +* +*********************) +FUNCTION TO_USINT__REAL : USINT + VAR_INPUT + in : REAL; + END_VAR + + TO_USINT__REAL := REAL_TO_USINT(in); +END_FUNCTION + +(******************** +* +* Converts REAL to INT +* +*********************) +FUNCTION TO_INT__REAL : INT + VAR_INPUT + in : REAL; + END_VAR + + TO_INT__REAL := REAL_TO_INT(in); +END_FUNCTION + +(******************** +* +* Converts REAL to UINT +* +*********************) +FUNCTION TO_UINT__REAL : UINT + VAR_INPUT + in : REAL; + END_VAR + + TO_UINT__REAL := REAL_TO_UINT(in); +END_FUNCTION + +(******************** +* +* Converts REAL to DINT +* +*********************) +FUNCTION TO_DINT__REAL : DINT + VAR_INPUT + in : REAL; + END_VAR + + TO_DINT__REAL := REAL_TO_DINT(in); +END_FUNCTION + +(******************** +* +* Converts REAL to UDINT +* +*********************) +FUNCTION TO_UDINT__REAL : UDINT + VAR_INPUT + in : REAL; + END_VAR + + TO_UDINT__REAL := REAL_TO_UDINT(in); +END_FUNCTION + +(******************** +* +* Converts REAL to LINT +* +*********************) +FUNCTION TO_LINT__REAL : LINT + VAR_INPUT + in : REAL; + END_VAR + + TO_LINT__REAL := REAL_TO_LINT(in); +END_FUNCTION + +(******************** +* +* Converts REAL to ULINT +* +*********************) +FUNCTION TO_ULINT__REAL : ULINT + VAR_INPUT + in : REAL; + END_VAR + + TO_ULINT__REAL := REAL_TO_ULINT(in); +END_FUNCTION + +(******************** +* +* Converts REAL to REAL +* +*********************) +FUNCTION TO_REAL__REAL : REAL + VAR_INPUT + in : REAL; + END_VAR + + TO_REAL__REAL := in; +END_FUNCTION + +(******************** +* +* Converts REAL to LREAL +* +*********************) +FUNCTION TO_LREAL__REAL : LREAL + VAR_INPUT + in : REAL; + END_VAR + + TO_LREAL__REAL := REAL_TO_LREAL(in); +END_FUNCTION + +(******************** +* +* Converts any other numerical value to LREAL +* +*********************) +FUNCTION TO_LREAL : LREAL + VAR_INPUT + in : T; + END_VAR +END_FUNCTION + +(******************** +* +* Converts LREAL to SINT +* +*********************) +FUNCTION TO_SINT__LREAL : SINT + VAR_INPUT + in : LREAL; + END_VAR + + TO_SINT__LREAL := LREAL_TO_SINT(in); +END_FUNCTION + +(******************** +* +* Converts LREAL to USINT +* +*********************) +FUNCTION TO_USINT__LREAL : USINT + VAR_INPUT + in : LREAL; + END_VAR + + TO_USINT__LREAL := LREAL_TO_USINT(in); +END_FUNCTION + +(******************** +* +* Converts LREAL to INT +* +*********************) +FUNCTION TO_INT__LREAL : INT + VAR_INPUT + in : LREAL; + END_VAR + + TO_INT__LREAL := LREAL_TO_INT(in); +END_FUNCTION + +(******************** +* +* Converts LREAL to UINT +* +*********************) +FUNCTION TO_UINT__LREAL : UINT + VAR_INPUT + in : LREAL; + END_VAR + + TO_UINT__LREAL := LREAL_TO_UINT(in); +END_FUNCTION + +(******************** +* +* Converts LREAL to DINT +* +*********************) +FUNCTION TO_DINT__LREAL : DINT + VAR_INPUT + in : LREAL; + END_VAR + + TO_DINT__LREAL := LREAL_TO_DINT(in); +END_FUNCTION + +(******************** +* +* Converts LREAL to UDINT +* +*********************) +FUNCTION TO_UDINT__LREAL : UDINT + VAR_INPUT + in : LREAL; + END_VAR + + TO_UDINT__LREAL := LREAL_TO_UDINT(in); +END_FUNCTION + +(******************** +* +* Converts LREAL to LINT +* +*********************) +FUNCTION TO_LINT__LREAL : LINT + VAR_INPUT + in : LREAL; + END_VAR + + TO_LINT__LREAL := LREAL_TO_LINT(in); +END_FUNCTION + +(******************** +* +* Converts LREAL to ULINT +* +*********************) +FUNCTION TO_ULINT__LREAL : ULINT + VAR_INPUT + in : LREAL; + END_VAR + + TO_ULINT__LREAL := LREAL_TO_ULINT(in); +END_FUNCTION + +(******************** +* +* Converts LREAL to REAL +* +*********************) +FUNCTION TO_REAL__LREAL : REAL + VAR_INPUT + in : LREAL; + END_VAR + + TO_REAL__LREAL := LREAL_TO_REAL(in); +END_FUNCTION + +(******************** +* +* Converts LREAL to LREAL +* +*********************) +FUNCTION TO_LREAL__LREAL : LREAL + VAR_INPUT + in : LREAL; + END_VAR + + TO_LREAL__LREAL := in; +END_FUNCTION + diff --git a/tests/lit/single/conversion/to_num.st b/tests/lit/single/conversion/to_num.st new file mode 100644 index 0000000000..e4210c43c2 --- /dev/null +++ b/tests/lit/single/conversion/to_num.st @@ -0,0 +1,245 @@ +// RUN: (%COMPILE %s && %RUN) | %CHECK %s +FUNCTION main + printf('%d$N', TO_SINT(SINT#5)); // CHECK: 5 + printf('%d$N', TO_SINT(USINT#5)); // CHECK: 5 + printf('%d$N', TO_SINT(INT#5)); // CHECK: 5 + printf('%d$N', TO_SINT(UINT#5)); // CHECK: 5 + printf('%d$N', TO_SINT(DINT#5)); // CHECK: 5 + printf('%d$N', TO_SINT(UDINT#5)); // CHECK: 5 + printf('%d$N', TO_SINT(LINT#5)); // CHECK: 5 + printf('%d$N', TO_SINT(ULINT#5)); // CHECK: 5 + + printf('%d$N', TO_USINT(SINT#5)); // CHECK: 5 + printf('%d$N', TO_USINT(USINT#5)); // CHECK: 5 + printf('%d$N', TO_USINT(INT#5)); // CHECK: 5 + printf('%d$N', TO_USINT(UINT#5)); // CHECK: 5 + printf('%d$N', TO_USINT(DINT#5)); // CHECK: 5 + printf('%d$N', TO_USINT(UDINT#5)); // CHECK: 5 + printf('%d$N', TO_USINT(LINT#5)); // CHECK: 5 + printf('%d$N', TO_USINT(ULINT#5)); // CHECK: 5 + + printf('%d$N', TO_INT(SINT#5)); // CHECK: 5 + printf('%d$N', TO_INT(USINT#5)); // CHECK: 5 + printf('%d$N', TO_INT(INT#5)); // CHECK: 5 + printf('%d$N', TO_INT(UINT#5)); // CHECK: 5 + printf('%d$N', TO_INT(DINT#5)); // CHECK: 5 + printf('%d$N', TO_INT(UDINT#5)); // CHECK: 5 + printf('%d$N', TO_INT(LINT#5)); // CHECK: 5 + printf('%d$N', TO_INT(ULINT#5)); // CHECK: 5 + + printf('%d$N', TO_UINT(SINT#5)); // CHECK: 5 + printf('%d$N', TO_UINT(USINT#5)); // CHECK: 5 + printf('%d$N', TO_UINT(INT#5)); // CHECK: 5 + printf('%d$N', TO_UINT(UINT#5)); // CHECK: 5 + printf('%d$N', TO_UINT(DINT#5)); // CHECK: 5 + printf('%d$N', TO_UINT(UDINT#5)); // CHECK: 5 + printf('%d$N', TO_UINT(LINT#5)); // CHECK: 5 + printf('%d$N', TO_UINT(ULINT#5)); // CHECK: 5 + + printf('%d$N', TO_DINT(SINT#5)); // CHECK: 5 + printf('%d$N', TO_DINT(USINT#5)); // CHECK: 5 + printf('%d$N', TO_DINT(INT#5)); // CHECK: 5 + printf('%d$N', TO_DINT(UINT#5)); // CHECK: 5 + printf('%d$N', TO_DINT(DINT#5)); // CHECK: 5 + printf('%d$N', TO_DINT(UDINT#5)); // CHECK: 5 + printf('%d$N', TO_DINT(LINT#5)); // CHECK: 5 + printf('%d$N', TO_DINT(ULINT#5)); // CHECK: 5 + + printf('%d$N', TO_UDINT(SINT#5)); // CHECK: 5 + printf('%d$N', TO_UDINT(USINT#5)); // CHECK: 5 + printf('%d$N', TO_UDINT(INT#5)); // CHECK: 5 + printf('%d$N', TO_UDINT(UINT#5)); // CHECK: 5 + printf('%d$N', TO_UDINT(DINT#5)); // CHECK: 5 + printf('%d$N', TO_UDINT(UDINT#5)); // CHECK: 5 + printf('%d$N', TO_UDINT(LINT#5)); // CHECK: 5 + printf('%d$N', TO_UDINT(ULINT#5)); // CHECK: 5 + + printf('%d$N', TO_LINT(SINT#5)); // CHECK: 5 + printf('%d$N', TO_LINT(USINT#5)); // CHECK: 5 + printf('%d$N', TO_LINT(INT#5)); // CHECK: 5 + printf('%d$N', TO_LINT(UINT#5)); // CHECK: 5 + printf('%d$N', TO_LINT(DINT#5)); // CHECK: 5 + printf('%d$N', TO_LINT(UDINT#5)); // CHECK: 5 + printf('%d$N', TO_LINT(LINT#5)); // CHECK: 5 + printf('%d$N', TO_LINT(ULINT#5)); // CHECK: 5 + + printf('%d$N', TO_ULINT(SINT#5)); // CHECK: 5 + printf('%d$N', TO_ULINT(USINT#5)); // CHECK: 5 + printf('%d$N', TO_ULINT(INT#5)); // CHECK: 5 + printf('%d$N', TO_ULINT(UINT#5)); // CHECK: 5 + printf('%d$N', TO_ULINT(DINT#5)); // CHECK: 5 + printf('%d$N', TO_ULINT(UDINT#5)); // CHECK: 5 + printf('%d$N', TO_ULINT(LINT#5)); // CHECK: 5 + printf('%d$N', TO_ULINT(ULINT#5)); // CHECK: 5 + + + // REAL and LREAL tests, where we want to see rounding + + printf('%d$N', TO_SINT(REAL#4.0)); // CHECK: 4 + printf('%d$N', TO_SINT(REAL#4.1)); // CHECK: 4 + printf('%d$N', TO_SINT(REAL#4.2)); // CHECK: 4 + printf('%d$N', TO_SINT(REAL#4.3)); // CHECK: 4 + printf('%d$N', TO_SINT(REAL#4.4)); // CHECK: 4 + printf('%d$N', TO_SINT(REAL#4.5)); // CHECK: 5 + printf('%d$N', TO_SINT(REAL#4.6)); // CHECK: 5 + printf('%d$N', TO_SINT(REAL#4.7)); // CHECK: 5 + printf('%d$N', TO_SINT(REAL#4.8)); // CHECK: 5 + printf('%d$N', TO_SINT(REAL#4.9)); // CHECK: 5 + printf('%d$N', TO_SINT(LREAL#4.0)); // CHECK: 4 + printf('%d$N', TO_SINT(LREAL#4.1)); // CHECK: 4 + printf('%d$N', TO_SINT(LREAL#4.2)); // CHECK: 4 + printf('%d$N', TO_SINT(LREAL#4.3)); // CHECK: 4 + printf('%d$N', TO_SINT(LREAL#4.4)); // CHECK: 4 + printf('%d$N', TO_SINT(LREAL#4.5)); // CHECK: 5 + printf('%d$N', TO_SINT(LREAL#4.6)); // CHECK: 5 + printf('%d$N', TO_SINT(LREAL#4.7)); // CHECK: 5 + printf('%d$N', TO_SINT(LREAL#4.8)); // CHECK: 5 + printf('%d$N', TO_SINT(LREAL#4.9)); // CHECK: 5 + + printf('%d$N', TO_USINT(REAL#4.0)); // CHECK: 4 + printf('%d$N', TO_USINT(REAL#4.1)); // CHECK: 4 + printf('%d$N', TO_USINT(REAL#4.2)); // CHECK: 4 + printf('%d$N', TO_USINT(REAL#4.3)); // CHECK: 4 + printf('%d$N', TO_USINT(REAL#4.4)); // CHECK: 4 + printf('%d$N', TO_USINT(REAL#4.5)); // CHECK: 5 + printf('%d$N', TO_USINT(REAL#4.6)); // CHECK: 5 + printf('%d$N', TO_USINT(REAL#4.7)); // CHECK: 5 + printf('%d$N', TO_USINT(REAL#4.8)); // CHECK: 5 + printf('%d$N', TO_USINT(REAL#4.9)); // CHECK: 5 + printf('%d$N', TO_USINT(LREAL#4.0)); // CHECK: 4 + printf('%d$N', TO_USINT(LREAL#4.1)); // CHECK: 4 + printf('%d$N', TO_USINT(LREAL#4.2)); // CHECK: 4 + printf('%d$N', TO_USINT(LREAL#4.3)); // CHECK: 4 + printf('%d$N', TO_USINT(LREAL#4.4)); // CHECK: 4 + printf('%d$N', TO_USINT(LREAL#4.5)); // CHECK: 5 + printf('%d$N', TO_USINT(LREAL#4.6)); // CHECK: 5 + printf('%d$N', TO_USINT(LREAL#4.7)); // CHECK: 5 + printf('%d$N', TO_USINT(LREAL#4.8)); // CHECK: 5 + printf('%d$N', TO_USINT(LREAL#4.9)); // CHECK: 5 + + printf('%d$N', TO_INT(REAL#4.0)); // CHECK: 4 + printf('%d$N', TO_INT(REAL#4.1)); // CHECK: 4 + printf('%d$N', TO_INT(REAL#4.2)); // CHECK: 4 + printf('%d$N', TO_INT(REAL#4.3)); // CHECK: 4 + printf('%d$N', TO_INT(REAL#4.4)); // CHECK: 4 + printf('%d$N', TO_INT(REAL#4.5)); // CHECK: 5 + printf('%d$N', TO_INT(REAL#4.6)); // CHECK: 5 + printf('%d$N', TO_INT(REAL#4.7)); // CHECK: 5 + printf('%d$N', TO_INT(REAL#4.8)); // CHECK: 5 + printf('%d$N', TO_INT(REAL#4.9)); // CHECK: 5 + printf('%d$N', TO_INT(LREAL#4.0)); // CHECK: 4 + printf('%d$N', TO_INT(LREAL#4.1)); // CHECK: 4 + printf('%d$N', TO_INT(LREAL#4.2)); // CHECK: 4 + printf('%d$N', TO_INT(LREAL#4.3)); // CHECK: 4 + printf('%d$N', TO_INT(LREAL#4.4)); // CHECK: 4 + printf('%d$N', TO_INT(LREAL#4.5)); // CHECK: 5 + printf('%d$N', TO_INT(LREAL#4.6)); // CHECK: 5 + printf('%d$N', TO_INT(LREAL#4.7)); // CHECK: 5 + printf('%d$N', TO_INT(LREAL#4.8)); // CHECK: 5 + printf('%d$N', TO_INT(LREAL#4.9)); // CHECK: 5 + + printf('%d$N', TO_UINT(REAL#4.0)); // CHECK: 4 + printf('%d$N', TO_UINT(REAL#4.1)); // CHECK: 4 + printf('%d$N', TO_UINT(REAL#4.2)); // CHECK: 4 + printf('%d$N', TO_UINT(REAL#4.3)); // CHECK: 4 + printf('%d$N', TO_UINT(REAL#4.4)); // CHECK: 4 + printf('%d$N', TO_UINT(REAL#4.5)); // CHECK: 5 + printf('%d$N', TO_UINT(REAL#4.6)); // CHECK: 5 + printf('%d$N', TO_UINT(REAL#4.7)); // CHECK: 5 + printf('%d$N', TO_UINT(REAL#4.8)); // CHECK: 5 + printf('%d$N', TO_UINT(REAL#4.9)); // CHECK: 5 + printf('%d$N', TO_UINT(LREAL#4.0)); // CHECK: 4 + printf('%d$N', TO_UINT(LREAL#4.1)); // CHECK: 4 + printf('%d$N', TO_UINT(LREAL#4.2)); // CHECK: 4 + printf('%d$N', TO_UINT(LREAL#4.3)); // CHECK: 4 + printf('%d$N', TO_UINT(LREAL#4.4)); // CHECK: 4 + printf('%d$N', TO_UINT(LREAL#4.5)); // CHECK: 5 + printf('%d$N', TO_UINT(LREAL#4.6)); // CHECK: 5 + printf('%d$N', TO_UINT(LREAL#4.7)); // CHECK: 5 + printf('%d$N', TO_UINT(LREAL#4.8)); // CHECK: 5 + printf('%d$N', TO_UINT(LREAL#4.9)); // CHECK: 5 + + printf('%d$N', TO_DINT(REAL#4.0)); // CHECK: 4 + printf('%d$N', TO_DINT(REAL#4.1)); // CHECK: 4 + printf('%d$N', TO_DINT(REAL#4.2)); // CHECK: 4 + printf('%d$N', TO_DINT(REAL#4.3)); // CHECK: 4 + printf('%d$N', TO_DINT(REAL#4.4)); // CHECK: 4 + printf('%d$N', TO_DINT(REAL#4.5)); // CHECK: 5 + printf('%d$N', TO_DINT(REAL#4.6)); // CHECK: 5 + printf('%d$N', TO_DINT(REAL#4.7)); // CHECK: 5 + printf('%d$N', TO_DINT(REAL#4.8)); // CHECK: 5 + printf('%d$N', TO_DINT(REAL#4.9)); // CHECK: 5 + printf('%d$N', TO_DINT(LREAL#4.0)); // CHECK: 4 + printf('%d$N', TO_DINT(LREAL#4.1)); // CHECK: 4 + printf('%d$N', TO_DINT(LREAL#4.2)); // CHECK: 4 + printf('%d$N', TO_DINT(LREAL#4.3)); // CHECK: 4 + printf('%d$N', TO_DINT(LREAL#4.4)); // CHECK: 4 + printf('%d$N', TO_DINT(LREAL#4.5)); // CHECK: 5 + printf('%d$N', TO_DINT(LREAL#4.6)); // CHECK: 5 + printf('%d$N', TO_DINT(LREAL#4.7)); // CHECK: 5 + printf('%d$N', TO_DINT(LREAL#4.8)); // CHECK: 5 + printf('%d$N', TO_DINT(LREAL#4.9)); // CHECK: 5 + + printf('%d$N', TO_UDINT(REAL#4.0)); // CHECK: 4 + printf('%d$N', TO_UDINT(REAL#4.1)); // CHECK: 4 + printf('%d$N', TO_UDINT(REAL#4.2)); // CHECK: 4 + printf('%d$N', TO_UDINT(REAL#4.3)); // CHECK: 4 + printf('%d$N', TO_UDINT(REAL#4.4)); // CHECK: 4 + printf('%d$N', TO_UDINT(REAL#4.5)); // CHECK: 5 + printf('%d$N', TO_UDINT(REAL#4.6)); // CHECK: 5 + printf('%d$N', TO_UDINT(REAL#4.7)); // CHECK: 5 + printf('%d$N', TO_UDINT(REAL#4.8)); // CHECK: 5 + printf('%d$N', TO_UDINT(REAL#4.9)); // CHECK: 5 + printf('%d$N', TO_UDINT(LREAL#4.0)); // CHECK: 4 + printf('%d$N', TO_UDINT(LREAL#4.1)); // CHECK: 4 + printf('%d$N', TO_UDINT(LREAL#4.2)); // CHECK: 4 + printf('%d$N', TO_UDINT(LREAL#4.3)); // CHECK: 4 + printf('%d$N', TO_UDINT(LREAL#4.4)); // CHECK: 4 + printf('%d$N', TO_UDINT(LREAL#4.5)); // CHECK: 5 + printf('%d$N', TO_UDINT(LREAL#4.6)); // CHECK: 5 + printf('%d$N', TO_UDINT(LREAL#4.7)); // CHECK: 5 + printf('%d$N', TO_UDINT(LREAL#4.8)); // CHECK: 5 + printf('%d$N', TO_UDINT(LREAL#4.9)); // CHECK: 5 + + printf('%d$N', TO_LINT(REAL#4.0)); // CHECK: 4 + printf('%d$N', TO_LINT(REAL#4.1)); // CHECK: 4 + printf('%d$N', TO_LINT(REAL#4.2)); // CHECK: 4 + printf('%d$N', TO_LINT(REAL#4.3)); // CHECK: 4 + printf('%d$N', TO_LINT(REAL#4.4)); // CHECK: 4 + printf('%d$N', TO_LINT(REAL#4.5)); // CHECK: 5 + printf('%d$N', TO_LINT(REAL#4.6)); // CHECK: 5 + printf('%d$N', TO_LINT(REAL#4.7)); // CHECK: 5 + printf('%d$N', TO_LINT(REAL#4.8)); // CHECK: 5 + printf('%d$N', TO_LINT(REAL#4.9)); // CHECK: 5 + printf('%d$N', TO_LINT(LREAL#4.0)); // CHECK: 4 + printf('%d$N', TO_LINT(LREAL#4.1)); // CHECK: 4 + printf('%d$N', TO_LINT(LREAL#4.2)); // CHECK: 4 + printf('%d$N', TO_LINT(LREAL#4.3)); // CHECK: 4 + printf('%d$N', TO_LINT(LREAL#4.4)); // CHECK: 4 + printf('%d$N', TO_LINT(LREAL#4.5)); // CHECK: 5 + printf('%d$N', TO_LINT(LREAL#4.6)); // CHECK: 5 + printf('%d$N', TO_LINT(LREAL#4.7)); // CHECK: 5 + printf('%d$N', TO_LINT(LREAL#4.8)); // CHECK: 5 + printf('%d$N', TO_LINT(LREAL#4.9)); // CHECK: 5 + + printf('%d$N', TO_ULINT(REAL#4.0)); // CHECK: 4 + printf('%d$N', TO_ULINT(REAL#4.1)); // CHECK: 4 + printf('%d$N', TO_ULINT(REAL#4.2)); // CHECK: 4 + printf('%d$N', TO_ULINT(REAL#4.3)); // CHECK: 4 + printf('%d$N', TO_ULINT(REAL#4.4)); // CHECK: 4 + printf('%d$N', TO_ULINT(REAL#4.5)); // CHECK: 5 + printf('%d$N', TO_ULINT(REAL#4.6)); // CHECK: 5 + printf('%d$N', TO_ULINT(REAL#4.7)); // CHECK: 5 + printf('%d$N', TO_ULINT(REAL#4.8)); // CHECK: 5 + printf('%d$N', TO_ULINT(REAL#4.9)); // CHECK: 5 + printf('%d$N', TO_ULINT(LREAL#4.0)); // CHECK: 4 + printf('%d$N', TO_ULINT(LREAL#4.1)); // CHECK: 4 + printf('%d$N', TO_ULINT(LREAL#4.2)); // CHECK: 4 + printf('%d$N', TO_ULINT(LREAL#4.3)); // CHECK: 4 + printf('%d$N', TO_ULINT(LREAL#4.4)); // CHECK: 4 + printf('%d$N', TO_ULINT(LREAL#4.5)); // CHECK: 5 + printf('%d$N', TO_ULINT(LREAL#4.6)); // CHECK: 5 + printf('%d$N', TO_ULINT(LREAL#4.7)); // CHECK: 5 + printf('%d$N', TO_ULINT(LREAL#4.8)); // CHECK: 5 + printf('%d$N', TO_ULINT(LREAL#4.9)); // CHECK: 5 +END_FUNCTION \ No newline at end of file