C#,数值计算——Ranhash的计算方法与源程序

C#,数值计算——Ranhash的计算方法与源程序_第1张图片

1 文本格式

using System;

namespace Legalsoft.Truffer
{
    ///


    /// High-quality random hash of an integer into several numeric types.
    ///

    public class Ranhash
    {
        public Ranhash()
        {
        }

        public ulong int64(ulong u)
        {
            ulong v = u * 3935559000370003845L + 2691343689449507681L;
            v ^= v >> 21;
            v ^= v << 37;
            v ^= v >> 4;
            v *= 4768777513237032717L;
            v ^= v << 20;
            v ^= v >> 41;
            v ^= v << 5;
            return v;
        }

        public uint int32(ulong u)
        {
            return (uint)((long)u & 0xffffffff);
        }

        ///


        /// Returns hash of u as a double-precision 
        /// floating value between 0. and 1.
        ///

        ///
        ///
        public double doub(ulong u)
        {
            double r = 5.42101086242752217E-20 * int64(u);
            return (r < 0.0) ? (1 + r) : r;
        }
    }
}
 

2 代码格式

using System;

namespace Legalsoft.Truffer
{
    /// 
    /// High-quality random hash of an integer into several numeric types.
    /// 
    public class Ranhash
    {
        public Ranhash()
        {
        }

        public ulong int64(ulong u)
        {
            ulong v = u * 3935559000370003845L + 2691343689449507681L;
            v ^= v >> 21;
            v ^= v << 37;
            v ^= v >> 4;
            v *= 4768777513237032717L;
            v ^= v << 20;
            v ^= v >> 41;
            v ^= v << 5;
            return v;
        }

        public uint int32(ulong u)
        {
            return (uint)((long)u & 0xffffffff);
        }

        /// 
        /// Returns hash of u as a double-precision 
        /// floating value between 0. and 1.
        /// 
        /// 
        /// 
        public double doub(ulong u)
        {
            double r = 5.42101086242752217E-20 * int64(u);
            return (r < 0.0) ? (1 + r) : r;
        }
    }
}

你可能感兴趣的:(C#数值计算,Numerical,Recipes,c#,数值计算,开发语言,算法)