Variant f_bcsqrt(CStrRef operand, int64 scale /* = -1 */) { if (scale < 0) scale = BCG(bc_precision); bc_num result; bc_init_num(&result); php_str2num(&result, (char*)operand.data()); Variant ret; if (bc_sqrt(&result, scale) != 0) { if (result->n_scale > scale) { result->n_scale = scale; } ret = String(bc_num2str(result), AttachString); } else { Logger::Warning("Square root of negative number"); } bc_free_num(&result); return ret; }
static Variant HHVM_FUNCTION(bcsqrt, const String& operand, int64_t scale /* = -1 */) { if (scale < 0) scale = BCG(bc_precision); bc_num result; bc_init_num(&result); php_str2num(&result, (char*)operand.data()); Variant ret; if (bc_sqrt(&result, scale) != 0) { if (result->n_scale > scale) { result->n_scale = scale; } ret = String(bc_num2str(result), AttachString); } else { raise_warning("Square root of negative number"); } bc_free_num(&result); return ret; }
// square root BigNumber BigNumber::sqrt () const { BigNumber result (*this); bc_sqrt (&result.num_, scale_); return result; } // end of BigNumber::sqrt