Changeset 4249


Ignore:
Timestamp:
Feb 9, 2007, 3:26:03 PM (18 years ago)
Author:
ole
Message:

Made get_machine_precision() fast by using precomputed, global variable.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/utilities/numerical_tools.py

    r3945 r4249  
    2626# Note, INF is used instead of NAN (Not a number), since Numeric has no NAN
    2727# if we use a package that has NAN, this should be updated to use NAN.
     28
     29# Static variable used by get_machine_precision
     30machine_precision = None
    2831
    2932
     
    303306def get_machine_precision():
    304307    """Calculate the machine precision for Floats
    305     """
    306 
    307     epsilon = 1.
    308     while epsilon/2 + 1. > 1.:
    309         epsilon /= 2
    310 
    311     return epsilon   
     308
     309    Depends on static variable machine_precision in this module
     310    as this would otherwise require too much computation.
     311    """
     312
     313    global machine_precision
     314   
     315    if machine_precision is None:
     316        epsilon = 1.
     317        while epsilon/2 + 1. > 1.:
     318            epsilon /= 2
     319
     320        machine_precision = epsilon
     321
     322    return machine_precision   
    312323
    313324####################################################################
Note: See TracChangeset for help on using the changeset viewer.