push
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
#include <math.h>
|
||||
|
||||
int abs(int n) {
|
||||
return n >= 0 ? n : -n;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
double fabs(double x) {
|
||||
union {
|
||||
double d;
|
||||
uint64_t i;
|
||||
} u = { .d = x };
|
||||
|
||||
u.i &= 0x7FFFFFFFFFFFFFFFULL;
|
||||
return u.d;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int isinf(double x) {
|
||||
union {
|
||||
double f;
|
||||
uint64_t i;
|
||||
} u = { .f = x };
|
||||
|
||||
uint64_t exp = (u.i >> 52) & 0x7FF;
|
||||
uint64_t mantissa = u.i & 0xFFFFFFFFFFFFFULL;
|
||||
|
||||
return (exp == 0x7FF) && (mantissa == 0);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
#include <math.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int isnan(double x) {
|
||||
union {
|
||||
double f;
|
||||
uint64_t i;
|
||||
} u = { .f = x };
|
||||
|
||||
uint64_t exp = (u.i >> 52) & 0x7FF;
|
||||
uint64_t mantissa = u.i & 0xFFFFFFFFFFFFFULL;
|
||||
|
||||
return (exp == 0x7FF) && (mantissa != 0);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#include <math.h>
|
||||
|
||||
double pow(double x, double y) {
|
||||
if (y == 0.0) return 1.0;
|
||||
|
||||
if (y == (int)y) {
|
||||
int n = (int)y;
|
||||
double result = 1.0;
|
||||
|
||||
if (n > 0) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
result *= x;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < -n; i++) {
|
||||
result /= x;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if (x > 0.0) {
|
||||
int int_part = (int)y;
|
||||
double frac_part = y - int_part;
|
||||
|
||||
double int_pow = pow(x, int_part);
|
||||
|
||||
if (frac_part > 0.0) {
|
||||
return int_pow * (1.0 + frac_part * (x - 1.0));
|
||||
} else {
|
||||
return int_pow / (1.0 - frac_part * (x - 1.0));
|
||||
}
|
||||
}
|
||||
|
||||
return NAN;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#include <math.h>
|
||||
|
||||
double pow10(int n) {
|
||||
double result = 1.0;
|
||||
|
||||
if (n >= 0) {
|
||||
for (int i = 0; i < n; i++) {
|
||||
result *= 10.0;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < -n; i++) {
|
||||
result /= 10.0;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user