Opened 8 years ago

Closed 8 years ago

#1238 closed defect (fixed)

WCPS1.5_Difference value when casting expression

Reported by: Bang Pham Huu Owned by: Bang Pham Huu
Priority: major Milestone: 10.0
Component: petascope Version: development
Keywords: WCPS 2.0, difference between casting Cc: Dimitar Misev, Vlad Merticariu, Peter Baumann
Complexity: Medium

Description

test wcps "11_vegetation_index_computation.test.out" with WCPS query

for s in ( rgb ) return encode(
(unsigned char) (s.0 - s.1)/(s.0 + s.1), "png", "nodata=0" )

with Rasql from WCPS1.0 (6533 bytes)

select encode((char)((((((s).0)-((s).1)))/((((s).0)+((s).1))))),
"PNG",
"nodata=0;xmin=0.0;xmax=399.0;ymin=0.0;ymax=343.0;crs=OGC:Index2D") from rgb AS s where oid(s)=45057

and Rasql from WCPS1.5 (8147 bytes)

SELECT encode((char)  ( s.0 - s.1 )  /  ( s.0 + s.1 ) , "png" , "nodata=0") FROM rgb AS s

The difference is from casting to char, when WCPS1.0 try (char)(expression1 / expression2) and WCPS1.5
try (char)(epression1) / (expression2)

I think WCPS1.5 is correct and need to update oracle?

Change History (11)

comment:1 by Bang Pham Huu, 8 years ago

Dimitar, can you confirm? then I will update oracle for this test case also.

comment:2 by Dimitar Misev, 8 years ago

Bang, can you check in the WCPS manual about precedence of cast? Is

(unsigned char) (s.0 - s.1)/(s.0 + s.1)

equivalent to

(unsigned char) ((s.0 - s.1)/(s.0 + s.1))

or

((unsigned char) (s.0 - s.1)) / (s.0 + s.1)

comment:3 by Bang Pham Huu, 8 years ago

Dimitar, How can I get this document? Thanks.

comment:4 by Dimitar Misev, 8 years ago

Cc: Peter Baumann added

cast should have higher precedence than division normally, although the WCPS standard is a bit unclear and I think it specifies division as having higher precedence.

Peter can you comment?

in reply to:  3 comment:5 by Dimitar Misev, 8 years ago

Replying to bphamhuu:

Dimitar, How can I get this document? Thanks.

You can get the WCPS standard from the OGC website.

comment:6 by Dimitar Misev, 8 years ago

I think it's an error in the WCPS standard, cast should be in between these two likely in section 7.2.4 Operator precedence rules

  • unary arithmetic, trigonometric, and exponential functions
  • * , /

comment:7 by Peter Baumann, 8 years ago

when designing WCPS I had in mind what common PLs do, such as described here for C++:
http://en.cppreference.com/w/cpp/language/operator_precedence
that means: cast has among the highest precedences;
parentheses, of course, always are our friends.

But there might be another issue: early on in rasql we had made the mistake to say "division result type = input type" which yielded an integer division. After correcting this to "for input int and float, division result is double", expressions like NDVI worked as expected.

in reply to:  7 comment:8 by Dimitar Misev, 8 years ago

Replying to pbaumann:

when designing WCPS I had in mind what common PLs do, such as described here for C++:
http://en.cppreference.com/w/cpp/language/operator_precedence
that means: cast has among the highest precedences;
parentheses, of course, always are our friends.

Yes I expected this too. So WCPS1.5 is indeed correct here.

comment:9 by Bang Pham Huu, 8 years ago

ok, that is what I want to hear, thanks.

comment:10 by Bang Pham Huu, 8 years ago

Owner: set to Bang Pham Huu
Status: newassigned

comment:11 by Bang Pham Huu, 8 years ago

Resolution: fixed
Status: assignedclosed

the patch was accepted, close ticket, thanks.

Note: See TracTickets for help on using tickets.