I try to compute  x = (2**83 + 1)/3 which is mathematically an integer and a float in python-x. In python 2, I get :   x = 2**83 + 1 x = 9671406556917033397649409L   then   y = x/3 = 3223802185639011132549803L   In python 3, I get :   x = 2**83 + 1 x = 9671406556917033397649409 --&gt; OK   then  y = x/3 = 3.223802185639011e+24   To compare the 2 results, I use a format string instruction in python 3: z = '%25d' % y and I get z = '3223802185639010953592832' and z = '3223802185639011132549803' in python 2. (%i gives the same results, quite normal). The strange thing is that when I compute 3*Z, I get the good result in python2 and a wrong one in python3. I can't see where the problem is with my test (computing, formatting, ...). I'd like to use python 3 and to display x = (2**83 + 1)/3 with no 'e+24' but with all numbers.  Does anybody have an idea?  I have to add thet the problem remains the same when using / or // in python2. We get the same result sinc it is mathematically an integer. I should say that the problem is rather with python 3. How can i get the good result (the whole dispaly of (2**83 + 1)/3 in python 3) ?
27
Consider the following code:   0.1 + 0.2 == 0.3  -&gt;  false   0.1 + 0.2         -&gt;  0.30000000000000004   Why do these inaccuracies happen?
114176
I know that  $\left ( -1 \right )^{2/3}=\left ( \left ( -1 \right )^{2} \right )^{1/3}=1$  But Matlab computes this as $- 0.5 + 0.8660254038i$ a complex number.Why?
8128
What is the best possible way to check if a string can be represented as a number in Python?   The function I currently have right now is:  def is_number(s):     try:         float(s)         return True     except ValueError:         return False   Which, not only is ugly and slow, seems clunky. However I haven't found a better method because calling float in the main function is even worse.
40474
I have a Python function that takes a numeric argument that must be an integer in order for it behave correctly. What is the preferred way of verifying this in Python?  My first reaction is to do something like this:  def isInteger(n):     return int(n) == n   But I can't help thinking that this is 1) expensive 2) ugly and 3) subject to the tender mercies of machine epsilon.   Does Python provide any native means of type checking variables? Or is this considered to be a violation of the language's dynamically typed design?  EDIT: since a number of people have asked - the application in question works with IPv4 prefixes, sourcing data from flat text files. If any input is parsed into a float, that record should be viewed as malformed and ignored.
28318
I'm trying to format numbers. Examples:  1     =&gt; 1 12    =&gt; 12 123   =&gt; 123 1234  =&gt; 1,234 12345 =&gt; 12,345   It strikes as a fairly common thing to do but I can't figure out which filter I'm supposed to use.  Edit: If you've a generic Python way to do this, I'm happy adding a formatted field in my model.
26280
What is an easy way in Python to format integers into strings representing thousands with K, and millions with M, and leaving just couple digits after comma?  I'd like to show 7436313 as 7.44M, and 2345 as 2,34K.  Is there some % string formatting operator available for that? Or that could be done only by actually dividing by 1000 in a loop and constructing result string step by step?
77118
I will use binary.  I claim to have a bijection $f \colon \mathcal{N} \to \left[ 0, 1 \right)$ where $\mathcal{N}$ is the set of natural numbers $\left\{ 0, 1, 10, 11, 100, \dotsc \right\}$ as follows:  $$ \begin{array}{l|l} x \in \mathcal{N} &amp; f(x) \in \left[ 0, 1 \right)\\\hline 0 &amp; 0.0 \\ 1 &amp; 0.1 \\ 10 &amp; 0.01 \\ 11 &amp; 0.11 \\ 100 &amp; 0.001 \\ 101 &amp; 0.011 \\ 110 &amp; 0.101 \\ 111 &amp; 0.111 \\ 1000 &amp; 0.0001 \\ \hspace{.6em}\vdots &amp; \hspace{.9em}\vdots \end{array} $$  It's basically the .  I claim to have everything on this list.  Diagonalization?  Go ahead!  Constructing a number that differs from $f(i + 1)$ in its $i$-th fractional digit yields $0.11111\!\ldots = 0.\overline{1}$ which is $1$, and that should not be on the list anyway!  Why does this not work? I think it has something to do with integers supposedly not having infinite digits, while reals supposedly do.
102992
I  have come up with the following expression to convert 5.1234   to   5° 7`24.24"   toint ($x) || '° ' || toint((($x) - toint ($x)) * 60) ||'`' || substr( (tostring(((($x) - toint ($x)) * 60) - toint((($x) - toint ($x)) * 60)) * 60),1,5) || '"'  Here’s the problem : for some  points such as 5.1234, it works. but for others,  it doesn’t.  I suspect the problem is the integer conversion which round up the decimal figures instead of truncating it.  Is there any other option? thanks.
63140
Following from  question, I came up with another interesting question: What is  $(-1)^{\frac{2}{3}}$?  Wolfram alpha  it equals to some weird complex number (-0.5 +0.866... i), but when I try I do this: $(-1)^{\frac{2}{3}}={((-1)^2)}^{\frac{1}{3}}=1^{\frac{1}{3}}=1$.If it has multiple "answers", should we even call it a "number"? Because if we don't, it would be a bit different from what we were taught in elementary school. I actually thought if it doesn't have a variable in it, it should be a number.  I'm a bit confused. Which one is correct and why? I would appreciate any help.
111060
My approach:  let $x=3 \lambda, y=4 \lambda,z=5 \lambda $ where $\lambda \in \mathbb Z$ ,then $x^2+y^2=z^2 \implies $ $(3 \lambda)^2+(4 \lambda)^2=(5 \lambda)^2$  Since $xyz=60 \lambda^3$ &amp; $60 \lambda^3 \equiv0 \pmod{60}$ $\implies xyz \equiv0 \pmod{60}$  Hence proved!  Is it correct?  Is there any alternative method of doing this?
111701
I'm messing around with some C code using floats, and I'm getting 1.#INF00, -1.#IND00 and -1.#IND when I try to print floats in the screen. What does those values mean?  I believe that 1.#INF00 means positive infinity, but what about -1.#IND00 and -1.#IND? I also saw sometimes this value: 1.$NaN which is Not a Number, but what causes those strange values and how can those help me with debugging?  I'm using  which I believe uses  representation for float point numbers.  Can someone list all those invalid values and what they mean?
69977
$$\frac{1}{3}=.33\bar{3}$$    is a rational number, but the $3$ keeps on repeating indefinitely (infinitely?). How is this a ratio if it shows this continuous pattern instead of being a finite ratio?    I understand that $\pi$ is irrational because it extends infinitely without repetition, but I am confused about what makes $1/3=.3333\bar{3}$ rational. It is clearly repeating, but when you apply it to a number, the answers are different: $.33$ and $.3333$ are part of the same concept, $1/3$, yet:  $.33$ and $.3333$ are different numbers:    $.33/2=.165$ and $.3333/2=.16665$, yet they are both part of $1/3$.   How is $1/3=.33\bar{3}$ rational?
57093
I think there's a lot for me to learn about data types. Why this happens  double result = ((3/8)*100).ToString();   it gives zero .. should be 37,5 ... :(
73750
I need to find out how to format numbers as strings. My code is here:  return str(hours)+":"+str(minutes)+":"+str(seconds)+" "+ampm   Hours and minutes are integers, and seconds is a float.  the str() function will convert all of these numbers to the tenths (0.1) place.  So instead of my string outputting "5:30:59.07 pm", it would display something like "5.0:30.0:59.1 pm".  Bottom line, what library / function do I need to do this for me?
122014
$x^3 + y^2 +z=\overline{zyx}$, where $\overline{zyx}$ denotes the sequence of the digits.  $x^3 +y^2 +z =100z+10y+x$,where $x,y,z&gt;0$  The maximum value of $x$, $y$, $z$ individually can only be $9$.  $\text{Maximum value}= 9^3 + 9^2 + 9 = 819$  So, $100z+10y+z&lt;819$  Then I'm lost here a bit. What do I do next?
10585
Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like  [2,2,2] - [1,1,1] = [1,1,1]   Should I use tuples?  If none of them defines these operands on these types, can I define it instead?  If not, should I create a new vector3 class?
12708
In python, you can have a function return multiple values.  Here's a contrived example:  def divide(x, y):     quotient = x/y     remainder = x % y     return quotient, remainder    (q, r) = divide(22, 7)   This seems very useful, but it looks like it can also be abused ("Well..function X already computes what we need as an intermediate value.  Let's have X return that value also").  When should you draw the line and define a different method?