Changeset 3849


Ignore:
Timestamp:
Oct 24, 2006, 4:14:51 PM (16 years ago)
Author:
ole
Message:

Added function and test for calculating machine precision for Python Floats

Location:
anuga_core/source/anuga/utilities
Files:
2 edited

Legend:

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

    r3749 r3849  
    288288    return bins
    289289
    290 
     290def get_machine_precision():
     291    """Calculate the machine precision for Floats
     292    """
     293
     294    epsilon = 1.
     295    while epsilon/2 + 1. > 1.:
     296        epsilon /= 2
     297
     298    return epsilon   
    291299
    292300####################################################################
  • anuga_core/source/anuga/utilities/test_numerical_tools.py

    r3514 r3849  
    186186
    187187
     188    def test_machine_precision(self):
     189        """test_machine_precision(self):
     190        Test the function that calculates epsilon. As this varies on
     191        different machines, this is only an indication.
     192        """
     193
     194        eps = get_machine_precision()
     195
     196        assert eps < 1.0e-12, 'Machine precision should be better than 1.0e-12'
     197        assert eps > 0.0
     198        assert 1.0+eps/2 == 1.0
     199       
     200       
    188201    def test_histogram(self):
    189202        """Test histogram with different bin boundaries
Note: See TracChangeset for help on using the changeset viewer.