Python‎ > ‎decimal‎ > ‎

Decimal.is_normal()

http://www.adilwaseem.com/
Introduction
Return True if the argument is a normal finite
non-zero number with an adjusted exponent greater than or equal to Emin. Return False if the argument is zero, subnormal, infinite or a NaN.

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

Parameters
x=decimal value

Examples
The returns are:
 >>> Decimal('infinity').is_normal()
False
>>> Decimal('-infinity').is_normal()
False
>>> Decimal(0).is_normal()
False
>>> 
>>> Decimal(99.33).is_normal()
True
>>>

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):

    
    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