0
Maximum "binary" size of float in python
I've been testing my code: https://code.sololearn.com/c9Y5O3Zs6l1S/?ref=app i've done it on offline (64-bit os, Python 3) and at number 2^56-1 it went wrong, last prime it wrote was 4 (yes, it's not prime), I think it could be problem with float size in python does anyone know what's size of float in python (in bytes would be perfect)
5 Antworten
+ 3
See this thread here. I just saw in StackOverflow to use Numpy.float128
https://www.sololearn.com/Discuss/2664261/how-to-solve-JUMP_LINK__&&__python__&&__JUMP_LINK-float-numbers-inaccuracy
+ 1
You can use numpy.finfo to get information:
from numpy import finfo
print(finfo(float).bits)
# to get more information:
print(finfo(float))
Output:
64
Machine parameters for float64
---------------------------------------------------------------
precision = 15 resolution = 1.0000000000000001e-15
machep = -52 eps = 2.2204460492503131e-16
negep = -53 epsneg = 1.1102230246251565e-16
minexp = -1022 tiny = 2.2250738585072014e-308
maxexp = 1024 max = 1.7976931348623157e+308
nexp = 11 min = -max
---------------------------------------------------------------
0
is there some library for intagers bigger than 64 bits?
0
Does it help to replace exponents with multiplication? That might remove unwanted floating point operations.
Change line 10 from:
while i % p[c] > 0 and p[c] ** 2 < i:
To:
while i % p[c] > 0 and p[c] * p[c] < i:
Line 24 from:
while i < len(nums) or nums[-1] < num ** 0.5:
To:
while i < len(nums) or nums[-1] * nums[-1] < num:
0
Problem with floating point happens because it's too large number - i gues they convert themself to float (Python does this automaticaly) and using modulo on too big float is useless