private def buildNumericComparison(c: NumericComparison[_]) : ExpHolder =
buildBinaryOperation(getBinaryOpInfo(c.getOperation), buildExpression(c.getLeft), buildExpression(c.getRight))
- private def buildNumericOperator(o: NumericOperator[_]) : ExpHolder =
- buildBinaryOperation(getBinaryOpInfo(o.getOperation), buildExpression(o.getLeft), buildExpression(o.getRight))
+ private def buildNumericOperator(o: NumericOperator[_]) : ExpHolder = {
+ val left = buildExpression(o.getLeft)
+ var right = buildExpression(o.getRight)
+
+ // Fortran has stupid rules about unary negation on the right hand side of an arithmetic operator.
+ def isUnaryNegate(expression: Expression[_]) = expression match {
+ case (l: FloatLiteral) if l.getValue < 0 => true
+ case (l: IntegerLiteral) if l.getValue < 0 => true
+ case _ => false
+ }
+
+ if (isUnaryNegate(o.getRight))
+ right = ExpHolder(maxPrec, "(%s)".format(right.exp))
+
+ buildBinaryOperation(getBinaryOpInfo(o.getOperation), left, right)
+ }
private def processForLoop(stat: ForLoop) {
val index = stat.getIndex