Returns -1 if input is false, or 1 if input is true.
Project description
boolean_to_signed
Returns -1 if input is false, or 1 if input is true.
Install
$ pip install boolean_to_signed
Usage
from boolean_to_signed import to_signed
print(to_signed(False)); #=> -1
print(to_signed(True)); #=> 1
# use cases
x = y = value = 0
# using naive conditional assignment
if x > 0:
y += value
else:
y -= value;
# using direct assignment
y += to_signed(x > 0) * value;
About
Author
Najim Islam
License
Copyright © 2021, Najim Islam. Released under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for boolean_to_signed-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 998aa337b78b2266893f66e2e7edf89df316a1a4aecbd99907ac0312027f2480 |
|
MD5 | 08433d362d532bb03389794d2011e072 |
|
BLAKE2b-256 | 59937ed8cd4d480140309b147025ce725cdbfa68554c790e4d831e4c9016fa29 |