PageRenderTime 23ms CodeModel.GetById 16ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/lib/numeric/real_32.e

http://github.com/tybor/Liberty
Specman e | 118 lines | 72 code | 19 blank | 27 comment | 1 complexity | 55c62ca8e43f5f3db01816f7b95f4f94 MD5 | raw file
  1-- This file is part of a Liberty Eiffel library.
  2-- See the full copyright at the end.
  3--
  4expanded class REAL_32
  5
  6insert
  7   REAL_GENERAL
  8
  9feature {ANY} -- Conversions:
 10   to_real_64: REAL_64
 11         -- Explicit conversion to REAL_64.
 12      do
 13         Result := Current
 14      ensure
 15         Current = Result
 16      end
 17
 18   to_real_extended: REAL_EXTENDED
 19         -- Explicit conversion to REAL_EXTENDED.
 20      do
 21         Result := Current
 22      ensure
 23         Current = Result
 24      end
 25
 26   to_real_80: REAL_80
 27         -- Explicit conversion to REAL_80.
 28      do
 29         Result := Current
 30      ensure
 31         Current = Result
 32      end
 33
 34   to_real_128: REAL_128
 35         -- Explicit conversion to REAL_128.
 36      do
 37         Result := Current
 38      ensure
 39         Current = Result
 40      end
 41
 42   force_to_integer_64: INTEGER_64
 43      external "built_in"
 44      end
 45
 46   force_to_integer_32: INTEGER_32
 47      external "built_in"
 48      end
 49
 50   force_to_integer_16: INTEGER_16
 51      external "built_in"
 52      end
 53
 54   force_to_natural_64: NATURAL_64
 55      external "built_in"
 56      end
 57
 58   force_to_natural_32: NATURAL_32
 59      external "built_in"
 60      end
 61
 62   force_to_natural_16: NATURAL_16
 63      external "built_in"
 64      end
 65
 66feature {ANY}
 67   zero: REAL_32 {REAL_32 0.0}
 68
 69   one: REAL_32 {REAL_32 1.0}
 70
 71   infix "~=" (other: like Current): BOOLEAN
 72      do
 73         Result := (Current - other).abs * ({REAL_32 2.0} ^ (mantissa_bits - precision)) <= Current.abs
 74      end
 75
 76   hash_code: INTEGER
 77      do
 78         Result := force_to_integer_32
 79         if Result < 0 then
 80            Result := -(Result + 1)
 81         end
 82      end
 83
 84   mantissa_bits: INTEGER_8 23
 85
 86   exponent_bits: INTEGER_8 8
 87
 88feature {}
 89   sprintf (buffer: NATIVE_ARRAY[CHARACTER]; mode: CHARACTER; f: INTEGER; value: REAL_64)
 90      external "plug_in"
 91      alias "{
 92         location: "${sys}/runtime"
 93         module_name: "basic_sprintf"
 94         feature_name: "sprintf_real_64"
 95         }"
 96      end
 97
 98end -- class REAL_32
 99--
100-- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
101--
102-- Permission is hereby granted, free of charge, to any person obtaining a copy
103-- of this software and associated documentation files (the "Software"), to deal
104-- in the Software without restriction, including without limitation the rights
105-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
106-- copies of the Software, and to permit persons to whom the Software is
107-- furnished to do so, subject to the following conditions:
108--
109-- The above copyright notice and this permission notice shall be included in
110-- all copies or substantial portions of the Software.
111--
112-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
113-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
114-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
115-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
116-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
117-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
118-- THE SOFTWARE.