Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,963 questions

51,905 answers

573 users

How to calculate logarithm for float numbers in Python

2 Answers

0 votes
import math 
  
for i in [0.1, 1.3, 2.6, 3.14, 4, 0]:         
   try:    
     print('{:2.1f} {:.18f}'.format(i, math.lgamma(i)))            
   except ValueError as err:                
     print('Error calculate lgamma({}): {}'.format(i, err))



'''
run:

0.1 2.252712651734205540
1.3 -0.108174809507860292
2.6 0.357411863548979358
3.1 0.826138704777028998
4.0 1.791759469228055401
Error calculate lgamma(0): math domain error

'''

 



answered Jul 13, 2019 by avibootz
0 votes
import math 
  
for i in [0.1, 1.3, 2.6, 3.14, 4, 0]:         
   try:    
     print('{:2.1f} {:.18f}'.format(i, math.log(math.gamma(i))))            
   except ValueError as err:                
     print('Error calculate lgamma({}): {}'.format(i, err))



'''
run:

0.1 2.252712651734205984
1.3 -0.108174809507860237
2.6 0.357411863548979802
3.1 0.826138704777028332
4.0 1.791759469228054957
Error calculate lgamma(0): math domain error

'''

 



answered Jul 13, 2019 by avibootz

Related questions

2 answers 203 views
1 answer 118 views
1 answer 195 views
1 answer 191 views
1 answer 154 views
...