exponentiation

How to reverse fixed point binary log algorithm for fractional power of 2?

陌路散爱 提交于 2020-04-30 06:28:19
问题 I found a fast binary logarithm algorithm for fixed points in an answer to this question: Fast fixed point pow, log, exp and sqrt, based on an algorithm by Clay S. Turner. Is it possible to "reverse" this to calculate fractional powers of two? e.g: // log2(3) = 1.5849609375 log2fix(196608, 16) == 103872 pow2fix(103872, 16) == 196608 Here's the code from Dan Moulding: #include <errno.h> #include <stddef.h> #include "log2fix.h" int32_t log2fix (uint32_t x, size_t precision) { int32_t b = 1U <<

Why Modular Exponentiation functions work differently in Python and Javascript for large numbers?

此生再无相见时 提交于 2020-02-25 09:52:46
问题 I need to perform modular exponentiation on quite large numbers on both python3 and javascript. I have functions that do the task, but they give me different outputs. Python (all of the three work in the same way): pow(176672119508, 55, 200000023499) def expmod_iter(a,b,c): x = 1 while(b>0): if(b&1==1): x = (x*a)%c a=(a*a)%c b >>= 1 return x%c def pow_mod(x, y, z): number = 1 while y: if y & 1: number = number * x % z y >>= 1 x = x * x % z return number # The result is always 124912252967 and

Can this script have better performance using modular exponentiation?

人走茶凉 提交于 2020-01-24 01:37:16
问题 def f(a, b, c): return ((a ** b)-1) // c % b Can this script be faster in some way? (I have been looking for something with modular exponentiation): pow(a, b, c) == a ** b % c but this above script doesn't seem to be improvable like that. Does anyone know a way to speedup the above script? Thanks in advance. Edit: The second script is not at all the same as the first one, it is just meant to show what kind of optimization I had in mind. Edit: I didn't put the exact equation in becouse I

How to compute a^b^c mod p?

妖精的绣舞 提交于 2020-01-15 07:28:30
问题 I am trying to compute a^b^c mod p for some positive integers a,b,c,p. One possible (and obvious) way is to use fast modular exponentiation which will run in O(log(b^c))=clog(b) . While I don't mind the efficiency here, the obvious downfall of this method is that you need an explicit binary representation of b^c which in itself is already exponential. So the question for me is, if I can not represent b^c as a binary representation, is there a way I can compute a^b^c mod p from the binary

first n digits of an exponentiation

怎甘沉沦 提交于 2020-01-09 19:33:34
问题 How do i determine the first n digits of an exponentiation (a b ). eg: for a = 12, b = 13 & n = 4, the first 4 digits are 1069. 回答1: Calculate a b by the following iterations: a 1 = a 1 , a 2 = a 2 , ... a i = a i , ... a b = a b You have a i+1 = a i ×a . Calcluate each a i not exactly. The thing is that the relative error of a b is less than n times relative error of a . You want to get final relative error less than 10 -n . Thus relative error on each step may be . Remove last digits at

first n digits of an exponentiation

谁说胖子不能爱 提交于 2020-01-09 19:33:12
问题 How do i determine the first n digits of an exponentiation (a b ). eg: for a = 12, b = 13 & n = 4, the first 4 digits are 1069. 回答1: Calculate a b by the following iterations: a 1 = a 1 , a 2 = a 2 , ... a i = a i , ... a b = a b You have a i+1 = a i ×a . Calcluate each a i not exactly. The thing is that the relative error of a b is less than n times relative error of a . You want to get final relative error less than 10 -n . Thus relative error on each step may be . Remove last digits at

In 10. power / calculation / Power calculations

半世苍凉 提交于 2020-01-09 05:34:06
问题 i am working on an apps for calculating fuel... i need to know how i can power a number in 10? the Excel code is "10^1.5" 回答1: If you mean in XCode, you have to #include <math.h> and then you can use pow : double res=pow(10, 1.5); 来源: https://stackoverflow.com/questions/5810108/in-10-power-calculation-power-calculations

Exponentiation of real numbers

纵饮孤独 提交于 2020-01-07 05:43:22
问题 I've come across an interesting exercise and it says: Implement a function x^y using standard functions of Turbo Pascal For integer variables I can use for loop but I cannot understand how to work with real variables in this case. I've been thinking about how to do this using Taylor series (can't understand how to use it for exponentiation) and I also found out that x^y = exp(y*log(x)) but there is only ln (natural logarithm) in standard functions... PS I'm not asking you to write code: give

power of in x86 assembly

不羁的心 提交于 2020-01-06 08:11:12
问题 as a starter in ASM programming i am need to get the result of 2 to the power of 38 in Assembly , and i need your help in understanding why is my program doesn't produce the result i am need (it prints 4 decimal): .386 .model flat, stdcall option casemap:none include \masm32\include\windows.inc include \masm32\include\msvcrt.inc includelib \masm32\lib\msvcrt.lib .data formatstr db "%d",0 .code start: mov eax , 2 mov ecx , 38 mov esi , eax mov edx , 0 .while TRUE mul esi mov esi, edx add esi,

Squaring Numbers in java using Math.pow getting error of precision

泄露秘密 提交于 2020-01-05 08:47:13
问题 I have do to a question to write a method to input an array of type LONG that stores the values of all the powers of 2 from 0 to 63 (i.e. 2 0 to 2 63 ) Output the contects of the array screen. Hint: Math.pow(x,y) is ued to put number x to exponent y so far I have something like I keep getting error or Math.pow(size,2); required long, found double. I tried Math.pow(i,2); I get same error./ possible loss of precision ,, any help :) thanks class ws3q2 { public static void main(String[]args) {