Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Jan 2, 2025
1 parent 07e8dc5 commit 35f5acb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
7 changes: 3 additions & 4 deletions vlib/math/stats/stats_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,6 @@ fn test_kurtosis() {
fn test_skew() {
mut data := [10.0, 4.45, 5.9, 2.7]
mut o := stats.skew(data)
dump(o)
assert math.alike(o, 0.5754021106320453)
data = [-3.0, 67.31, 4.4, 1.89]
o = stats.skew(data)
Expand All @@ -485,13 +484,13 @@ fn test_quantile() {

mut data := [2.7, 4.45, 5.9, 10.0]
mut o := stats.quantile(data, 0.1)!
assert math.alike(o, 3.2249999046325684)
assert math.alike(o, 3.225)
data = [-3.0, 1.89, 4.4, 67.31]
o = stats.quantile(data, 0.2)!
assert math.alike(o, -0.06600001454353333)
assert math.alike(o, -0.06599999999999961)
data = [7.88, 12.0, 54.83, 76.122]
o = stats.quantile(data, 0.3)!
assert math.alike(o, 11.588000297546387)
assert math.alike(o, 11.588)

stats.quantile(data, -0.3) or { assert err.msg() == 'index out of range' }

Expand Down
4 changes: 3 additions & 1 deletion vlib/v/gen/c/infix.v
Original file line number Diff line number Diff line change
Expand Up @@ -1188,8 +1188,10 @@ fn (mut g Gen) gen_plain_infix_expr(node ast.InfixExpr) {
&& node.op in [.plus, .minus, .mul, .div, .mod] && !(g.pref.translated
|| g.file.is_translated)
if needs_cast {
typ_str := if g.comptime.is_comptime(node.left) {
typ_str := if !node.left.is_literal() && g.comptime.is_comptime(node.left) {
g.styp(g.type_resolver.get_type_or_default(node.left, node.promoted_type))
} else if !node.right.is_literal() && g.comptime.is_comptime(node.right) {
g.styp(g.type_resolver.get_type_or_default(node.right, node.promoted_type))
} else {
g.styp(node.promoted_type)
}
Expand Down
13 changes: 10 additions & 3 deletions vlib/v/type_resolver/type_resolver.v
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ pub fn (mut t TypeResolver) get_type_or_default(node ast.Expr, default_typ ast.T
return t.get_type_or_default(node.expr, default_typ)
}
ast.InfixExpr {
if node.op in [.plus, .minus, .mul, .div, .mod] {
if !node.left.is_literal() && node.op in [.plus, .minus, .mul, .div, .mod] {
return t.get_type_or_default(node.left, default_typ)
}
if !node.right.is_literal() && node.op in [.plus, .minus, .mul, .div, .mod] {
return t.get_type_or_default(node.right, default_typ)
}
}
ast.IndexExpr {
if node.left is ast.Ident && node.left.ct_expr {
Expand Down Expand Up @@ -199,8 +202,12 @@ pub fn (mut t TypeResolver) get_type(node ast.Expr) ast.Type {
return t.table.value_type(nltype_unwrapped)
} else if node is ast.ParExpr && t.info.is_comptime(node.expr) {
return t.get_type(node.expr)
} else if node is ast.InfixExpr && t.info.is_comptime(node.left) {
return t.get_type(node.left)
} else if node is ast.InfixExpr {
if !node.left.is_literal() && t.info.is_comptime(node.left) {
return t.get_type(node.left)
} else if !node.right.is_literal() && t.info.is_comptime(node.right) {
return t.get_type(node.right)
}
} else if node is ast.CastExpr && node.typ.has_flag(.generic) {
return t.resolver.unwrap_generic(node.typ)
}
Expand Down

0 comments on commit 35f5acb

Please sign in to comment.