Export (0) Print
Expand All
Expand Minimize

LanguagePrimitives.DivideByInt<^T> Function (F#)

Divides a value by an integer.

Namespace/Module Path: Microsoft.FSharp.Core.LanguagePrimitives

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
DivideByInt : ^T -> int -> ^T (requires ^T with static member DivideByInt)

// Usage:
DivideByInt x y

x

Type: ^T

The dividend, or numerator.

y

Type: int

The divisor, or denominator.

The quotient.

If a type supports DivideByInt, the type supports exact division (floating-point division), rather than integer division, which rounds down to the nearest integer result.

Functions like Seq.average work only if the element type supports exact division. If you try to use Seq.average with an integer sequence, you get an error that indicates that the element type must implement DivideByInt. Typically, you can resolve this error by using Seq.averageBy and adding a cast to a floating-point value. The following code shows how to use Seq.averageBy with an integer sequence.

let average = [ 1 .. 10 ]
              |> Seq.averageBy (fun elem -> float elem)
printfn "%f" average 

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

F# Core Library VersionsF# Core Library Versions

Supported in: 2.0, 4.0, PortablePortable2.0, 4.0, Portable

Show:
© 2014 Microsoft