2017-06-27 02:41:47 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Andrew Kelley
|
|
|
|
*
|
|
|
|
* This file is part of zig, which is MIT licensed.
|
|
|
|
* See http://opensource.org/licenses/MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef ZIG_BIGFLOAT_HPP
|
|
|
|
#define ZIG_BIGFLOAT_HPP
|
|
|
|
|
|
|
|
#include "bigint.hpp"
|
|
|
|
#include "error.hpp"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
|
2017-09-14 13:44:22 +08:00
|
|
|
#include "softfloat_types.h"
|
|
|
|
|
2017-09-11 04:05:18 +08:00
|
|
|
|
2017-06-27 02:41:47 +08:00
|
|
|
struct BigFloat {
|
2017-09-14 13:44:22 +08:00
|
|
|
float128_t value;
|
2017-06-27 02:41:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct Buf;
|
|
|
|
|
2018-06-27 22:20:04 +08:00
|
|
|
void bigfloat_init_16(BigFloat *dest, float16_t x);
|
2017-08-20 12:33:05 +08:00
|
|
|
void bigfloat_init_32(BigFloat *dest, float x);
|
|
|
|
void bigfloat_init_64(BigFloat *dest, double x);
|
2017-09-14 13:44:22 +08:00
|
|
|
void bigfloat_init_128(BigFloat *dest, float128_t x);
|
2017-06-27 02:41:47 +08:00
|
|
|
void bigfloat_init_bigfloat(BigFloat *dest, const BigFloat *x);
|
|
|
|
void bigfloat_init_bigint(BigFloat *dest, const BigInt *op);
|
|
|
|
int bigfloat_init_buf_base10(BigFloat *dest, const uint8_t *buf_ptr, size_t buf_len);
|
|
|
|
|
2018-06-27 22:20:04 +08:00
|
|
|
float16_t bigfloat_to_f16(const BigFloat *bigfloat);
|
2017-08-20 12:33:05 +08:00
|
|
|
float bigfloat_to_f32(const BigFloat *bigfloat);
|
|
|
|
double bigfloat_to_f64(const BigFloat *bigfloat);
|
2017-09-14 13:44:22 +08:00
|
|
|
float128_t bigfloat_to_f128(const BigFloat *bigfloat);
|
2017-06-27 02:41:47 +08:00
|
|
|
|
|
|
|
void bigfloat_add(BigFloat *dest, const BigFloat *op1, const BigFloat *op2);
|
|
|
|
void bigfloat_negate(BigFloat *dest, const BigFloat *op);
|
|
|
|
void bigfloat_sub(BigFloat *dest, const BigFloat *op1, const BigFloat *op2);
|
|
|
|
void bigfloat_mul(BigFloat *dest, const BigFloat *op1, const BigFloat *op2);
|
|
|
|
void bigfloat_div(BigFloat *dest, const BigFloat *op1, const BigFloat *op2);
|
|
|
|
void bigfloat_div_trunc(BigFloat *dest, const BigFloat *op1, const BigFloat *op2);
|
|
|
|
void bigfloat_div_floor(BigFloat *dest, const BigFloat *op1, const BigFloat *op2);
|
|
|
|
void bigfloat_rem(BigFloat *dest, const BigFloat *op1, const BigFloat *op2);
|
|
|
|
void bigfloat_mod(BigFloat *dest, const BigFloat *op1, const BigFloat *op2);
|
2018-04-16 01:21:52 +08:00
|
|
|
void bigfloat_sqrt(BigFloat *dest, const BigFloat *op);
|
2017-08-20 12:33:05 +08:00
|
|
|
void bigfloat_append_buf(Buf *buf, const BigFloat *op);
|
2017-06-27 02:41:47 +08:00
|
|
|
Cmp bigfloat_cmp(const BigFloat *op1, const BigFloat *op2);
|
|
|
|
|
|
|
|
|
|
|
|
// convenience functions
|
|
|
|
Cmp bigfloat_cmp_zero(const BigFloat *bigfloat);
|
2017-08-08 03:57:41 +08:00
|
|
|
bool bigfloat_has_fraction(const BigFloat *bigfloat);
|
2017-06-27 02:41:47 +08:00
|
|
|
|
|
|
|
#endif
|