Skip to content

Commit

Permalink
Allow mwatt == '0.00' to work.
Browse files Browse the repository at this point in the history
  • Loading branch information
choppsv1 committed Apr 19, 2018
1 parent 0552232 commit 0611c83
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
opticalutil
===========

Support classes for handling optical power.

master branch status:

Expand Down
7 changes: 6 additions & 1 deletion opticalutil/power.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,12 @@ def from_mwatt(cls, mwatt):
return Power(None)
if not mwatt:
return Power(None)
# Should we do this?
try:
# Try and convert to float first to catch '0.00' case
if not float(mwatt):
return Power(None)
except ValueError:
pass

dBm = D(10, pcontext) * D(mwatt).log10(pcontext)
dBm = dBm.quantize(SIXPLACES, rounding=ROUND_HALF_EVEN)
Expand Down

0 comments on commit 0611c83

Please sign in to comment.