Skip to content

Commit

Permalink
index
Browse files Browse the repository at this point in the history
  • Loading branch information
douglascrockford committed Jan 20, 2018
1 parent 494a108 commit 5ac1952
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
26 changes: 13 additions & 13 deletions dec64_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dec64_math.c
Elementary functions for DEC64.
dec64.com
2017-06-03
2018-01-20
Public Domain
No warranty.
Expand Down Expand Up @@ -343,43 +343,43 @@ dec64 dec64_random() {
}
}

dec64 dec64_root(dec64 degree, dec64 radicand) {
dec64 dec64_root(dec64 index, dec64 radicand) {
dec64 result;
degree = dec64_normal(degree);
index = dec64_normal(index);
if (
dec64_is_any_nan(radicand) == DEC64_ONE
|| dec64_is_zero(degree) == DEC64_ONE
|| degree < 0
|| dec64_exponent(degree) != 0
|| dec64_is_zero(index) == DEC64_ONE
|| index < 0
|| dec64_exponent(index) != 0
|| (
radicand < 0
&& (dec64_coefficient(degree) & 1) == 0
&& (dec64_coefficient(index) & 1) == 0
)
) {
return DEC64_NAN;
}
if (dec64_is_zero(radicand) == DEC64_ONE) {
return DEC64_ZERO;
}
if (degree == DEC64_ONE) {
if (index == DEC64_ONE) {
return radicand;
}
if (degree == D_2) {
if (index == D_2) {
return dec64_sqrt(radicand);
}
dec64 degree_minus_one = dec64_dec(degree);
dec64 index_minus_one = dec64_dec(index);
result = DEC64_ONE;
dec64 prosult = DEC64_NAN;
while (1) {
dec64 progress = dec64_divide(
dec64_add(
dec64_multiply(result, degree_minus_one),
dec64_multiply(result, index_minus_one),
dec64_divide(
radicand,
dec64_exponentiate(result, degree_minus_one)
dec64_exponentiate(result, index_minus_one)
)
),
degree
index
);
if (progress == result) {
return result;
Expand Down
4 changes: 2 additions & 2 deletions dec64_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The dec64_math header file. This is the companion to dec64_math.c.
dec64.com
2017-01-22
2018-01-20
Public Domain
No warranty.
Expand All @@ -19,8 +19,8 @@ extern dec64 dec64_factorial(dec64 x);
extern dec64 dec64_log(dec64 x);
extern dec64 dec64_raise(dec64 coefficient, dec64 exponent);
extern dec64 dec64_random();
extern dec64 dec64_root(dec64 index, dec64 radicand);
extern void dec64_seed(dec64 seed);
extern dec64 dec64_sin(dec64 radians);
extern dec64 dec64_root(dec64 degree, dec64 radicand);
extern dec64 dec64_sqrt(dec64 radicand);
extern dec64 dec64_tan(dec64 radians);

0 comments on commit 5ac1952

Please sign in to comment.