Test Skin (click to toggle between A=2 and A=0):
Code: Select all
[Variables]
A=2
[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1
BackgroundMode=2
SolidColor=47,47,47,255
---Measures---
[B]
Measure=Calc
Formula=((#A#=0)?(0):(1/#A#))
DynamicVariables=1
---Meters---
[Result]
Meter=String
FontColor=255,255,255,255
FontFace=Consolas
FontSize=16
Padding=5,5,5,5
AntiAlias=1
Percentual=1
MeasureName=B
Text=B = %1%
LeftMouseUpAction=[!SetVariable A (2-#A#)][!UpdateMeasure *][!UpdateMeter *][!Redraw]
DynamicVariables=1
The meter never gets the 0% from the measure when A=0 per the conditional, because of the division by 0 error in the false branch, so it continues to display 50%.
Expected:
The conditional should properly avoid the division by 0 when A=0, by not evaluating the invalid 1/A altogether and returning 0%. According to this, the ternary operator seems to perform a short circuit operation in C++ and skip the non-true case in the conditional...
Notes:
- the result is converted to a percentage via the Percentual option, so 0 will be 0%, 0.5 will be 50%, and 1 will be 100%
- the division by 0 error can be avoided by making something like (1/((#A#=0)?(999):(#A#))) in the Formula, but in practice this is longer and more complex and the result won't exactly be 0