Opened 9 years ago
Closed 9 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:2 by , 9 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:4 by , 9 years ago
Cc: | 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?
comment:5 by , 9 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 , 9 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
- * , /
follow-up: 8 comment:7 by , 9 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.
comment:8 by , 9 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:10 by , 9 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:11 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
the patch was accepted, close ticket, thanks.