Decimal.is_finite()

http://www.adilwaseem.com/

Definition
Return True if the argument is a finite number, and False if the argument is infinite.

Syntax
Decimal(x).is_finite()-> bool

Parameters
x=Decimal

Examples
The return is:
 >>> Decimal(122.00).is_finite()
True
>>> Decimal(222.111345).is_finite()
True
>>> Decimal('infinity').is_finite()
False
>>>

def (Decimal attribute)
The method returns with Decimal attribute test as through define function and if statement.
from decimal import Decimal

def test (a,b,c,d,e,f,g,h,i):
a=Decimal(a).is_canonical()
b=Decimal(b).is_finite()
c=Decimal(c).is_infinite()
d=Decimal(d).is_nan()
e=Decimal(e).is_normal()
f=Decimal(f).is_signed()
g=Decimal(g).is_snan()
h=Decimal(h).is_subnormal()
i=Decimal(i).is_zero()

if a==True:
print("The Decimal(",value1,")is canonical.")
else:
print("The Decimal(",value1,")is not canonical.")

if b==True:
print("The Decimal(",value2,")is finite.")
else:
print("The Decimal(",value2,")is not finite.")

if c==True:
print("The Decimal(",value3,")is infinite.")
else:
print("The Decimal(",value3,")is not infinite.")

if d==True:
print("The Decimal(",value4,")is nan.")
else:
print("The Decimal(",value4,")is not nan.")

if e==True:
print("The Decimal(",value5,")is normal.")
else:
print("The Decimal(",value5,")is not normal.")

if f==True:
print("The Decimal(",value6,")is signed.")
else:
print("The Decimal(",value6,")is not signed.")

if g==True:
print("The Decimal(",value7,")is snan.")
else:
print("The Decimal(",value7,")is not snan.")


if h==True:
print("The Decimal(",value8,")is subnormal.")
else:
print("The Decimal(",value8,")is not subnormal.")

if i==True:
print("The Decimal(",value9,")is zero.")
else:
print("The Decimal(",value9,")is not zero.")

value1=1.1
value2=-2.1
value3='infinity'
value4=0
value5=1.21
value6=10
value7=.50
value8=.12
value9=.21

test(value1,value2,value3, value4, value5,value6,value7, value8, value9)

>>>
The Decimal( 1.1 )is canonical.
The Decimal( -2.1 )is finite.
The Decimal( infinity )is infinite.
The Decimal( 0 )is not nan.
The Decimal( 1.21 )is normal.
The Decimal( 10 )is not signed.
The Decimal( 0.5 )is not snan.
The Decimal( 0.12 )is not subnormal.
The Decimal( 0.21 )is not zero.
>>>


Comments