Added another F# implementation which more-closely follows the C implementation.