/*
     Description: 数学常用的工具函数

     Copyright : All right reserved by ICT

     Author : Zhang Zhonghai
     Date : 2025/12/26
*/
#pragma once

#include <limits>
#include <cstdint>
#include <cstdlib>
#include <cstring>

struct MathFunc {
    // 1.1 使用memcpy（最安全，无未定义行为）
    static int64_t doubleToRawLongBits(double value) {
        int64_t result;
        std::memcpy(&result, &value, sizeof(result));
        return result;
    }

    static double longBitsToDouble(int64_t bits) {
        double result;
        std::memcpy(&result, &bits, sizeof(result));
        return result;
    }

    static int floatToRawIntBits(float value) {
        int result;
        std::memcpy(&result, &value, sizeof(result));
        return result;
    }

    static float intBitsToFloat(int bits) {
        float result;
        std::memcpy(&result, &bits, sizeof(result));
        return result;
    }
};