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)

19th Jan 2021, 6:50 PM
nicolas turek
nicolas turek - avatar
5 Respuestas
20th Jan 2021, 1:59 AM
noteve
noteve - avatar
+ 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 ---------------------------------------------------------------
19th Jan 2021, 7:12 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
0
is there some library for intagers bigger than 64 bits?
19th Jan 2021, 7:17 PM
nicolas turek
nicolas turek - avatar
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:
19th Jan 2021, 8:25 PM
Brian
Brian - avatar
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
19th Jan 2021, 8:47 PM
nicolas turek
nicolas turek - avatar