// Souffle - A Datalog Compiler
// Copyright (c) 2020, The Souffle Developers. All rights reserved
// Licensed under the Universal Permissive License v 1.0 as shown at:
// - https://opensource.org/licenses/UPL
// - <souffle root>/licenses/SOUFFLE-UPL.txt

//
// Aggregate 5
//
// Test if aggregation works correctly with float
//

.decl A(x:float)
.decl C(x:float)
.output C

A(-55).
A(55).
A(0.5).
A(2).


C(y)                      :- y = max a : A(a).                 // 55
C(y)                      :- y = min a : A(a).                 // -55
C(y)                      :- y = sum a : {A(a)}.               // 2.5
C(to_float(y))            :- y = count : {A(_)}.               // 4
C(to_float(to_number(y))) :- y = mean x : {x = z + 1, A(z)}.   // 1
C(to_float(to_number(y))) :- y = mean x : A(x).                // 0
