Add `**` power operator
Following the example of Python. Motivation: https://github.com/bazelbuild/bazel-skylib/issues/282
I see no compelling reason for this feature. For powers of 2, use a shift. For anything else, use the math package.
Hello Adonovan can you please share the example of how to use Shift? I am trying to achieve below mention code. FYI this code is part of a telegraf conf file
[[processors.starlark]] source = ''' def apply(metric): # Conversion for A1 using the formula 10^(A1_raw - 5) as a float if "A1_raw" in metric.fields: metric.fields["A1"] = float(10 ** (metric.fields["A1_raw"] - 5))
# Conversion for A2 using the formula 10^(A2_raw/100 - 10) as a float
if "A2_raw" in metric.fields:
metric.fields["A2"] = float(10 ** ((metric.fields["A2_raw"] / 100) - 10))
return metric
'''
can you please share the example of how to use Shift?
Use << for integer operands, and math.pow for non-integers:
$ starlark
Welcome to Starlark (go.starlark.net)
>>> 1 << 8
256
>>> math.pow(2.0, 8.0)
256.0