Lines Matching defs:scale

55 bc_num_m(BcNum* a, BcNum* b, BcNum* restrict c, size_t scale);
129 * Set a number to 0 with the specified scale.
131 * @param scale The scale to set the number to.
134 bc_num_setToZero(BcNum* restrict n, size_t scale)
137 n->scale = scale;
219 * by to put its digits in the right place. For example, if the scale only
222 * @param scale The scale.
227 bc_num_leastSigPow(size_t scale)
231 digs = scale % BC_BASE_DIGS;
239 * of scale, like bc_num_int() is the opposite of rdx.
585 // rdx is to scale.
587 places_rdx = nrdx ? nrdx - BC_NUM_RDX(n->scale - places) : 0;
590 assert(places <= n->scale && (BC_NUM_ZERO(n) || places_rdx <= n->len));
592 n->scale -= places;
602 pow = bc_num_leastSigPow(n->scale);
625 // Easy case with zero; set the scale.
628 n->scale += places;
633 // rdx is to scale.
635 places_rdx = BC_NUM_RDX(places + n->scale) - nrdx;
648 // Finally, set scale and rdx.
650 n->scale += places;
653 assert(BC_NUM_RDX_VAL(n) == BC_NUM_RDX(n->scale));
660 bc_num_retireMul(BcNum* restrict n, size_t scale, bool neg1, bool neg2)
662 // Make sure scale is correct.
663 if (n->scale < scale) bc_num_extend(n, scale - n->scale);
664 else bc_num_truncate(n, n->scale - scale);
693 a->scale = b->scale = 0;
731 r->scale = 0;
825 if (places > n->scale)
827 size_t size = bc_vm_growSize(BC_NUM_RDX(places - n->scale), n->len);
831 // If zero, we can just set the scale and bail.
834 if (n->scale >= places) n->scale -= places;
835 else n->scale = 0;
854 if (n->scale)
861 size_t mod = n->scale % BC_BASE_DIGS, revdig;
888 // Set the scale appropriately.
889 if (places > n->scale)
891 n->scale = 0;
896 n->scale -= places;
897 BC_NUM_RDX_SET(n, BC_NUM_RDX(n->scale));
910 size_t places_rdx, scale, scale_mod, int_len, expand;
915 // If zero, we can just set the scale and bail.
918 n->scale += places;
919 bc_num_expand(n, BC_NUM_RDX(n->scale));
927 scale = n->scale;
929 // Figure out how the scale is affected.
930 scale_mod = scale % BC_BASE_DIGS;
961 n->scale = 0;
967 n->scale = scale + places;
968 BC_NUM_RDX_SET(n, BC_NUM_RDX(n->scale));
973 assert(BC_NUM_RDX_VAL(n) == BC_NUM_RDX(n->scale));
977 * Tests if a number is a integer with scale or not. Returns true if the number
1043 * doesn't need to use scale (per the bc spec), I am hijacking it to say whether
1230 c->scale = BC_MAX(a->scale, b->scale);
1237 * numbers gets low enough. This doesn't use scale because it treats the
1478 * @param scale The current scale.
1481 bc_num_m(BcNum* a, BcNum* b, BcNum* restrict c, size_t scale)
1501 ascale = a->scale;
1502 bscale = b->scale;
1504 // This sets the final scale according to the bc spec.
1505 scale1 = BC_MAX(scale, ascale);
1593 // The return parameter needs to have its scale set. This is the start. It
1689 * @param scale The current scale.
1693 size_t scale)
1729 c->scale = a->scale;
1792 assert(c->scale >= scale);
1793 rdx = BC_NUM_RDX_VAL(c) - BC_NUM_RDX(scale);
1875 * @param scale The current scale.
1878 bc_num_d(BcNum* a, BcNum* b, BcNum* restrict c, size_t scale)
1890 bc_num_setToZero(c, scale);
1897 bc_num_retireMul(c, scale, BC_NUM_NEG(a), BC_NUM_NEG(b));
1902 if (!BC_NUM_RDX_VAL(a) && !BC_NUM_RDX_VAL(b) && b->len == 1 && !scale)
1906 bc_num_retireMul(c, scale, BC_NUM_NEG(a), BC_NUM_NEG(b));
1910 len = bc_num_divReq(a, b, scale);
1936 cpa.scale = cpardx * BC_BASE_DIGS;
1938 // This is just setting up the scale in preparation for the division.
1939 bc_num_extend(&cpa, b->scale);
1940 cpardx = BC_NUM_RDX_VAL_NP(cpa) - BC_NUM_RDX(b->scale);
1942 cpa.scale = cpardx * BC_BASE_DIGS;
1944 // Once again, just setting things up, this time to match scale.
1945 if (scale > cpa.scale)
1947 bc_num_extend(&cpa, scale);
1949 cpa.scale = cpardx * BC_BASE_DIGS;
1968 cpb.scale = 0;
1971 bc_num_d_long(&cpa, &cpb, c, scale);
1973 bc_num_retireMul(c, scale, BC_NUM_NEG(a), BC_NUM_NEG(b));
1990 * @param scale The current scale.
1991 * @param ts The scale that the operation should be done to. Yes, it's not
1992 * necessarily the same as scale, per the bc spec.
1995 bc_num_r(BcNum* a, BcNum* b, BcNum* restrict c, BcNum* restrict d, size_t scale,
2025 bc_num_d(a, b, c, scale);
2028 if (scale) realscale = ts + 1;
2029 else realscale = scale;
2039 if (ts > d->scale && BC_NUM_NONZERO(d)) bc_num_extend(d, ts - d->scale);
2057 * @param scale The current scale.
2060 bc_num_rem(BcNum* a, BcNum* b, BcNum* restrict c, size_t scale)
2068 ts = bc_vm_growSize(scale, b->scale);
2069 ts = BC_MAX(ts, a->scale);
2080 bc_num_r(a, b, &c1, c, scale, ts);
2093 * @param scale The current scale.
2096 bc_num_p(BcNum* a, BcNum* b, BcNum* restrict c, size_t scale)
2128 bc_num_setToZero(c, scale);
2135 else bc_num_inv(a, c, scale);
2153 // set scale accordingly.
2156 size_t max = BC_MAX(scale, a->scale), scalepow;
2157 scalepow = bc_num_mulOverflow(a->scale, exp);
2160 else realscale = scale;
2164 for (powrdx = a->scale; !(exp & 1); exp >>= 1)
2199 if (c->scale > realscale) bc_num_truncate(c, c->scale - realscale);
2215 * @param scale The current scale.
2218 bc_num_place(BcNum* a, BcNum* b, BcNum* restrict c, size_t scale)
2222 BC_UNUSED(scale);
2227 if (val < c->scale) bc_num_truncate(c, c->scale - val);
2228 else if (val > c->scale) bc_num_extend(c, val - c->scale);
2235 bc_num_left(BcNum* a, BcNum* b, BcNum* restrict c, size_t scale)
2239 BC_UNUSED(scale);
2250 bc_num_right(BcNum* a, BcNum* b, BcNum* restrict c, size_t scale)
2254 BC_UNUSED(scale);
2279 * @param scale The current scale.
2283 bc_num_binary(BcNum* a, BcNum* b, BcNum* c, size_t scale, BcNumBinOp op,
2332 op(ptr_a, ptr_b, c, scale);
2472 // Set the scale of the number based on the location of the decimal point.
2475 n->scale = (size_t) (rdx *
2479 BC_NUM_RDX_SET(n, BC_NUM_RDX(n->scale));
2485 mod = n->scale % BC_BASE_DIGS;
2694 if (n->scale < digs) bc_num_extend(n, digs - n->scale);
2847 temp = n->scale % BC_BASE_DIGS;
3112 // Easy case. Even with scale, we just print this.
3173 bc_num_truncate(&intp, intp.scale);
3260 // If the number has a scale, then because we are printing just the
3262 // point plus at least one digit). So if there is a scale, a backslash
3275 !newline || (n->scale != 0 || i < stack.len - 1));
3279 if (!n->scale) goto err;
3303 fracp2.scale = n->scale;
3304 BC_NUM_RDX_SET_NP(fracp2, BC_NUM_RDX(fracp2.scale));
3306 // As long as we have not reached the scale of the number, keep printing.
3307 while ((idigits = bc_num_intDigits(n1)) <= n->scale)
3330 print(dig, len, radix, !newline || idigits != n->scale);
3471 d->scale = s->scale;
3495 return n->scale;
3504 if (BC_NUM_ZERO(n)) return n->scale ? n->scale : 1;
3513 size_t zero, scale;
3519 scale = n->scale % BC_BASE_DIGS;
3520 scale = scale ? scale : BC_BASE_DIGS;
3526 len = len * BC_BASE_DIGS - zero - (BC_BASE_DIGS - scale);
3528 // Otherwise, count the number of int digits and return that plus the scale.
3529 else len = bc_num_intDigits(n) + n->scale;
3733 frac.scale = n->scale;
3741 bc_num_truncate(&temp, temp.scale);
3977 bc_num_addReq(const BcNum* a, const BcNum* b, size_t scale)
3984 BC_UNUSED(scale);
4001 bc_num_mulReq(const BcNum* a, const BcNum* b, size_t scale)
4009 max = BC_NUM_RDX(scale);
4018 bc_num_divReq(const BcNum* a, const BcNum* b, size_t scale)
4022 // Division requires the length of the dividend plus the scale.
4026 max = BC_NUM_RDX(scale);
4035 bc_num_powReq(const BcNum* a, const BcNum* b, size_t scale)
4037 BC_UNUSED(scale);
4043 bc_num_placesReq(const BcNum* a, const BcNum* b, size_t scale)
4045 BC_UNUSED(scale);
4051 bc_num_add(BcNum* a, BcNum* b, BcNum* c, size_t scale)
4055 bc_num_binary(a, b, c, false, bc_num_as, bc_num_addReq(a, b, scale));
4059 bc_num_sub(BcNum* a, BcNum* b, BcNum* c, size_t scale)
4063 bc_num_binary(a, b, c, true, bc_num_as, bc_num_addReq(a, b, scale));
4067 bc_num_mul(BcNum* a, BcNum* b, BcNum* c, size_t scale)
4071 bc_num_binary(a, b, c, scale, bc_num_m, bc_num_mulReq(a, b, scale));
4075 bc_num_div(BcNum* a, BcNum* b, BcNum* c, size_t scale)
4079 bc_num_binary(a, b, c, scale, bc_num_d, bc_num_divReq(a, b, scale));
4083 bc_num_mod(BcNum* a, BcNum* b, BcNum* c, size_t scale)
4087 bc_num_binary(a, b, c, scale, bc_num_rem, bc_num_divReq(a, b, scale));
4091 bc_num_pow(BcNum* a, BcNum* b, BcNum* c, size_t scale)
4095 bc_num_binary(a, b, c, scale, bc_num_p, bc_num_powReq(a, b, scale));
4100 bc_num_places(BcNum* a, BcNum* b, BcNum* c, size_t scale)
4104 bc_num_binary(a, b, c, scale, bc_num_place, bc_num_placesReq(a, b, scale));
4108 bc_num_lshift(BcNum* a, BcNum* b, BcNum* c, size_t scale)
4112 bc_num_binary(a, b, c, scale, bc_num_left, bc_num_placesReq(a, b, scale));
4116 bc_num_rshift(BcNum* a, BcNum* b, BcNum* c, size_t scale)
4120 bc_num_binary(a, b, c, scale, bc_num_right, bc_num_placesReq(a, b, scale));
4125 bc_num_sqrt(BcNum* restrict a, BcNum* restrict b, size_t scale)
4143 // We want to calculate to a's scale if it is bigger so that the result will
4145 if (a->scale > scale) realscale = a->scale;
4146 else realscale = scale;
4234 x0->scale = x0->rdx = 0;
4262 if (b->scale > realscale) bc_num_truncate(b, b->scale - realscale);
4279 bc_num_divmod(BcNum* a, BcNum* b, BcNum* c, BcNum* d, size_t scale)
4294 ts = BC_MAX(scale + b->scale, a->scale);
4325 b->len == 1 && !scale)
4337 else bc_num_r(ptr_a, b, c, d, scale, ts);
4474 bc_file_printf(&vm->fout, " len: %zu, rdx: %zu, scale: %zu\n", name, n->len,
4475 BC_NUM_RDX_VAL(n), n->scale);
4482 ulong i, scale = n->scale;
4494 if (scale / BC_BASE_DIGS != BC_NUM_RDX_VAL(n) - i - 1)
4500 int mod = scale % BC_BASE_DIGS;
4515 bc_file_printf(&vm->ferr, "(%zu | %zu.%zu / %zu) %lu\n", n->scale, n->len,