## lustrec-tests / regression_tests / lustre_files / success / Simulink / src_many_files / datatypeconversion8_PP.LUSTREC.lus @ cd1faebc

History | View | Annotate | Download (1.35 KB)

1 | 4748b215 | hbourbou | -- This file has been generated by CoCoSim2. |
---|---|---|---|

2 | |||

3 | -- Compiler: Lustre compiler 2 (ToLustre.m) |
||

4 | -- Time: 03-Dec-2018 22:28:05 |
||

5 | #open <conv> |
||

6 | #open <lustrec_math> |
||

7 | node abs_int(x : int;) |
||

8 | returns(y : int;); |
||

9 | let |
||

10 | y = if (x >= 0) then |
||

11 | x |
||

12 | else (- x); |
||

13 | tel |
||

14 | |||

15 | |||

16 | node rem_int_int(x : int; |
||

17 | y : int;) |
||

18 | returns(z : int;); |
||

19 | let |
||

20 | z = if ((y = 0) or (x = 0)) then |
||

21 | 0 |
||

22 | else ((x mod y) - (if (((x mod y) <> 0) and (x <= 0)) then abs_int(y) else 0)); |
||

23 | tel |
||

24 | |||

25 | (* |
||

26 | --Rounds number to the nearest representable value. |
||

27 | *) |
||

28 | node _Convergent(x : real;) |
||

29 | returns(y : int;); |
||

30 | let |
||

31 | y = if (x > 0.5) then |
||

32 | if (fmod(x, 2.0) = 0.5) then |
||

33 | _Floor(x) |
||

34 | else _Floor((x + 0.5)) |
||

35 | else if (x >= (- 0.5)) then |
||

36 | 0 |
||

37 | else if (fmod(x, 2.0) = (- 0.5)) then |
||

38 | _Ceiling(x) |
||

39 | else _Ceiling((x - 0.5)); |
||

40 | tel |
||

41 | |||

42 | node int_to_uint16(x : int;) |
||

43 | returns(y : int;); |
||

44 | let |
||

45 | y = if (x > 65535) then |
||

46 | (0 + rem_int_int(( x - 65535 - 1 ), 65536)) |
||

47 | else if (x < 0) then |
||

48 | (65535 + rem_int_int(( x + 0 + 1 ), 65536)) |
||

49 | else x; |
||

50 | tel |
||

51 | |||

52 | (* |
||

53 | Original block name: datatypeconversion8_PP |
||

54 | *) |
||

55 | node datatypeconversion8_PP(In6_1 : real;) |
||

56 | returns(Out6_1 : int;); |
||

57 | var DataTypeConversion5_1 : int; |
||

58 | __time_step : real; |
||

59 | __nb_step : int; |
||

60 | let |
||

61 | DataTypeConversion5_1 = int_to_uint16(_Convergent(In6_1)); |
||

62 | Out6_1 = DataTypeConversion5_1; |
||

63 | __time_step = (0.0 -> ((pre __time_step) + 0.200000000000000)); |
||

64 | __nb_step = (0 -> ((pre __nb_step) + 1)); |
||

65 | tel |