you may look in the Pervasives.fs and Math folder of the distribution.

If it's not there, you can declare

1
let epsilon = System.Double.Epsilon

at the top of your module... Faster than writing the whole thing every time you need it.

By on 9/8/2006 1:00 AM ()

OCaml's epsilon_float is the smallest float that alters 1 under addition. The .NET System.Double.Epsilon appears to be the smallest positive float. That is called min_float in OCaml.

I also need epsilon_float. Can someone add it to .NET for us? :-)

By on 10/5/2006 4:14 PM ()

Right you are - min_float does indeed have a value in F# that is inconsistent with the value given in OCaml. Given the value is there for OCaml compatibility we'll adjust that. Though I note System.Double.Epsilon and OCaml's min_float are still slightly different.

I agree that it does not seem that epsilon_float is pre-defined on .NET. You can simply find the bit pattern that corresponds to the IEEE floating point number and call Int64.float_of_bits. OCaml says:

# Int64.bits_of_float epsilon_float;;
- : int64 = 4372995238176751616L

F# then says:

> 1.0 + (Int64.float_of_bits 4372995238176751616L) = 1.0;;

val it : bool = false

(Though note the F# Interactive printing of floating point numbers still prints "1" - we don't print numbers to their full precision by default, though you can change that - see [link:research.microsoft.com] for some details).

The IEEE 64-bit representation is very very fixed, so you can safely hardcode these wild integers.

By on 10/5/2006 4:42 PM ()

The difference in min_float may be down to denormalised arithmetic or 64- vs 80-bit precision.

While we're on the subject, even seemingly simple things like this are surprisingly complicated. You are quite right that the IEEE double is very very fixed in terms of specification. However, that specification is rarely adhered to. Intel and AMD CPUs often silently used 80-bits of precision when they can get away with it.

Consequently, the bytecode and nativecode OCaml compilers can produce different results for floating point computations because the native code compiler generates code that tries to leverage floating point registers and the computations are then done in 80-bit. See chapter 4 of "Objective CAML for Scientists" for more details and examples...

Cheers,

Jon.

By on 10/5/2006 5:34 PM ()

One follow up - I notice the documentation I pointed you to at [link:research.microsoft.com] is wrong. Here's the magic incarnation - the other settings on the "fsi" object are essentially as described at the link above.

#light

#r "FSharp.Interactive.Settings.dll"

open Microsoft.FSharp.Compiler.Interactive.Settings

fsi.FloatingPointFormat <- "g20"

1.0 + (Int64.float_of_bits 4372995238176751616L)

This incarnation won't change, but is not well documented.

By on 10/5/2006 4:57 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper