It's UWAweek 44 (2nd semester, 1st exam week)

help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.
Displaying the 2 articles in this topic
Showing 2 of 820 articles.
Currently 2 other people reading this forum.


 UWA week 37 (2nd semester, week 7) ↓
SVG not supported

Login to reply

👍?
helpful
1:12pm Sun 15th Sep, ANONYMOUS

Hi, If an ml file has the expression; "3 / 2". or for example: function divide(a, b) x <- a/b return x and then this is called as divide(3, 2). This will obviously be a problem when translated to C, as 3 and 2 will be treated as integers not doubles. Simply adding (double)("Expression") is also not suitable as there may be many operations in an expression. Can we assume that this will not occur, as part of the No invalid expressions condition provided by Chris? Or do we need to find a way to manage this.


SVG not supported

Login to reply

👍?
helpful
2:08pm Sun 15th Sep, Joshua N.

ANONYMOUS wrote:
> Hi, > > If an ml file has the expression; "3 / 2". or for example: > > function divide(a, b) > x <- a/b > return x > > and then this is called as divide(3, 2). This will obviously be a problem when translated to C, as 3 and 2 will be treated as integers not doubles. > > Simply adding (double)("Expression") is also not suitable as there may be many operations in an expression. > > Can we assume that this will not occur, as part of the No invalid expressions condition provided by Chris? Or do we need to find a way to manage this.
You can't pass "integers" to a function; the arguments are always doubles, so even if you pass 2, because the argument was defined to be a double, it will become 2.0. Every time you see a constant number, just put (double) in front of it or alternatively a decimal point and a zero, e.g. 2 becomes 2.0. I don't think you can ignore this issue as Chris explicitly uses constant integer values expecting the program to interpret them as doubles. However, Amitava said you can make assumptions and list them into a report, so maybe you don't anymore.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy