Table of contents
Collapse the table of content
Expand the table of content

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

Den Delimarsky|Last Updated: 7/5/2016
1 Contributor

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.

Return Value

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

Version Information

F# Core Library VersionsF# Core Library Versions

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

See Also

Core.LanguagePrimitives Module (F#)

Microsoft.FSharp.Core Namespace (F#)

© 2017 Microsoft