Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

boolean_to_signed-1.0.1.tar.gz (1.8 kB view hashes)

Uploaded Source

Built Distribution

boolean_to_signed-1.0.1-py3-none-any.whl (2.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page