What to do if you get a minus zero in Python

0 ÷ (negative number) = minus zero

In Python, if you calculate 0 ÷ negative numbers, the result will be -0.0.

n = 0.0/-1
print(n)
# =>-0.0

approach

You can remove the sign of -0.0 by adding 0.0.

n = 0.0/-1
print(n+0.)
# => 0.0

Demo

I have encountered this phenomenon in AOJ Question 0004 and have had trouble. I hope it helps people who are in trouble with minus zero.

Recommended Posts

What to do if you get a minus zero in Python
What to do if you get a "No versions found" error in pipenv
What to do if you get "coverage unknown" in Coveralls
What to do if you get "Python not configured." Using PyDev in Eclipse
[Python] What to do if you get a ModuleNotFoundError when importing pandas using Jupyter Notebook in Anaconda
What to do if you get `No kernel for language python found` in Hydrogen
What to do if you get an error when importing matplotlib in Python (Mac)
What to do if you get a UnicodeDecodeError with pip install
What to do to get google spreadsheet in python
What to do if you get Swagger-codegen in python and Import Error: No module named
What to do if you get a Cannot retrieve metalink for repository error in yum
What to do if there is a decimal in python json .dumps
What to do if you can't use scikit grid search in Python
What to do if you get lost in file reference with FileNotFoundError
What to do if you get angry in TensorFlow v2 without attribute'app'
What to do if you get a TypeError with numpy min, max
What happens if you do "import A, B as C" in Python?
What to do if a UnicodeDecodeError occurs in pip
What to do if you get a must override `get_config` error when trying to model.save in Keras
What to do if a Unicode Encode Error occurs in Sublime Text Python
What to do if you get an error when installing python with pyenv
[Python] What to check when you get a Unicode Decode Error in Django
What to do if ʻarguments [0] .scrollIntoView ();` fails in python selenium
Why do you add a main ()-if statement in Python?
What to do if pip gives a DistributionError in Homebrew
What to do if a 0xC0000005 error occurs in tf.train.start_queue_runners ()
What to do if you get angry with "Value Error: unknown local: UTF-8" in python manage.py syncdb
What to do if you can't log in as root
What to do if you get `locale.Error: unsupported locale setting` when getting the day of the week from a date in Python
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if you get a memory error when converting from PySparkDataFrame to PandasDataFrame
What to do if you get "(35,'SSL connect error')" in pycurl (one of them)
What to do if Sort imports get stuck in VS Code's Python Extension (around 2020/09)
What to do if you can't hit the arrow keys in the Python interactive console
What to do if you run python in IntelliJ and end with an error
How to get a stacktrace in python
What to do if you get an error when trying to send a message in tasks.loop () immediately after startup
What to do if you can't install pyaudio with pip #Python
If you want to assign csv export to a variable in python
Check if you can connect to a TCP port in Python
What to do if you can't use the trash in Lubuntu 18.04.
What to do if you get an error when running "certbot renew" in CakePHP environment
What to do if you get a Call with too many input arguments error at DoAndReturn in a golang test
What to do if you get the error RuntimeError: Python is not installed as a framework when trying to use matplitlib and pylab in Python 3.3
What to do if you can't pipenv shell
What to do if you can't find PDO in Laravel or CakePHP
What to do if you couldn't send an email to Yahoo with Python.
What to do if you get stuck during Anaconda installation on Linux
What to do if No Python documentation found for ... appears in pydoc
What to do if you get an error when trying to load mnist
What to do if you can't install with pip in babun environment
What to do if you get Could not fetch URL 443 with pip
What to do if you get an error when installing Dlib (Ubuntu)
What to do if you get an error saying c compiler cannot create executables in configure
[Python] What to do if an error occurs in pip (pyinstaller, pyautogui, etc.)
What to do if pip install fails in Xcode 5.1
What to do if you get angry with swapon failed: Operation not permitted
What to do if you can't pip install mysqlclient
What to do if you get an error like'Qstring' has already been set to version 1 using mne python
No module named What to do if you get'libs.resources'
ModuleNotFoundError: No module What to do if you get'tensorflow.contrib'