0

This might be dumb... but I'm having problems raising e to a negative number and I can't figure out what is going on.

>>> math.exp(((-23*(23-1))/730))
0.36787944117144233
>>> math.exp(-506/730)
0.36787944117144233
>>> math.exp(-.69)
0.5015760690660556
>>> math.exp(-(506/730))
1.0

For some reason I keep getting different answers when they should all be the same...
(506/730 is about 0.69)
Does anyone know what's happening?

Thanks!

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by dustbunny000
0

Maybe you are using Python 2, where integer division 506/730 makes 0, when you do not want that but actually 506.0/730 float division?

Better to get used to write in beginning of your programs:

from __future__ import division

So you get what you expect and must use // for integer division instead of single /

Edited by pyTony: n/a

0

Another way is to add '.' behind the integer to make it a 'float'.

506/730

to

506./730
0

This might be dumb... but I'm having problems raising e to a negative number and I can't figure out what is going on.

>>> math.exp(((-23*(23-1))/730))
0.36787944117144233
>>> math.exp(-506/730)
0.36787944117144233
>>> math.exp(-.69)
0.5015760690660556
>>> math.exp(-(506/730))
1.0

For some reason I keep getting different answers when they should all be the same...
(506/730 is about 0.69)
Does anyone know what's happening?

Thanks!

Thank you so much! I didn't realize it was that sensitive.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.