exponent

R: How can I calculate large numbers in n-choose-k? [duplicate]

你。 提交于 2020-05-13 04:11:06
问题 This question already has answers here : How would you program Pascal's triangle in R? (2 answers) How to work with large numbers in R? (1 answer) Closed 3 years ago . For a class assignment, I need to create a function that calculates n Choose k. I did just that, and it works fine with small numbers (e.g. 6 choose 2), but I'm supposed to get it work with 200 choose 50, where it naturally doesn't. The answer is too large and R outputs NaN or Inf, saying: > q5(200, 50) [1] "NaN" Warning

How to multiply by 2^n in assembly?

拟墨画扇 提交于 2020-01-30 08:08:40
问题 Given 2 numbers, x and n, what's the method to multiply x by 2^n ? For instance x=3.7 and n=5. so 3.7*2^5 = 118.4. I need this done without using the FPU commands (math coprocessor). So i figured that numbers in 32 bt processor are represented by 32 bits: the 1st is for the sign, next 8 (2-9) are for the exponent, and the following 23 are called the SIGNIFICAND. The exponent field is the k in 2^k. So what i need to do is only change the exponent field and add n to it. exponent = exponent + n

How to multiply by 2^n in assembly?

拈花ヽ惹草 提交于 2020-01-30 08:08:25
问题 Given 2 numbers, x and n, what's the method to multiply x by 2^n ? For instance x=3.7 and n=5. so 3.7*2^5 = 118.4. I need this done without using the FPU commands (math coprocessor). So i figured that numbers in 32 bt processor are represented by 32 bits: the 1st is for the sign, next 8 (2-9) are for the exponent, and the following 23 are called the SIGNIFICAND. The exponent field is the k in 2^k. So what i need to do is only change the exponent field and add n to it. exponent = exponent + n

Why does double.TryParse(“6E02”, out tempDouble) return true?

依然范特西╮ 提交于 2020-01-17 18:09:34
问题 It took me a day to figure out the problem that one of the if statement returns true for a string value. We are parsing to check whether the value is a number or a string. I found out that this statement used and when the string value comes in as 6E02 the statement return true that this is a double value. var double temp; var val ="6E02" result = double.TryParse(val, out temp) How can I fix this issue to return the result false for strings like (Number)E0(Number) Easy way I believe to check

Avoiding -inf when calculating Log Likelihood (MATLAB)

混江龙づ霸主 提交于 2020-01-15 23:38:16
问题 When using MATLAB to calculate Log_likelihood=log((1/1e8)*exp(-0.5*SSR)), if SSR (i.e. standard squared error) is large (e.g. SSR=1e4) then the exp() becomes zero and the Log_likelihood becomes -inf. Is there any numerical/mathematical trick that can handle this problem? Thank You 回答1: Assuming your log is a natural logarithm: log(a*exp(b)) = log(a) + log(exp(b)) = log(a) + b. Where a=(1/1e8) , b = -0.5*SSR Moreover, log(1/1e8) = log(1) - log(1e8) , so the above turns to be -log(1e8) + b ,

math overflow for a not very overflowing calculation in python

穿精又带淫゛_ 提交于 2020-01-07 05:10:24
问题 The calculation for which I'm getting the math overflow number is: e2 = math.exp([[-20.7313399283991]]) There are actually more extreme numbers that I've done than this, why is this causing an overflow? I get this error: OverflowError: math range error 回答1: math.exp() operates on scalars, not on matrices. You can use it like so, without the square brackets: >>> math.exp(-20.7313399283991) 9.919584164742123e-10 If you need to operate on a matrix, you could use numpy.exp(): >>> numpy.exp([[-20

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,

How do I quickly calculate a large positive, or negative, power of 2 in Java?

柔情痞子 提交于 2020-01-03 04:49:13
问题 I want to calculate powers of two larger than 2 62 , so I must store the result in a double and can't use the (1L << exp) trick. I also want to store fractions representing negative powers of two. 回答1: Java provides java.lang.Math.scalb(float f, int scaleFactor) for this. It multiplies f by 2 scaleFactor . 回答2: Since the IEEE 754 standard specifies a hidden bit, you can simply leave the 52-bit significand portion as 0 and only need to change the exponent portion, which is a biased unsigned

Extracting floating-point significand and exponent in NumPy

廉价感情. 提交于 2020-01-02 23:21:52
问题 I would like to be able to extract the significand and exponent of floating-point numbers in NumPy. Getting the exponent as an integer is fine and ok for the significand. Getting the significand as a bitfield would be even more convienient. I am aware that Python floats have a hex method; however, I wish to use numpy.float32 , numpy arrays, and ufuncs. I am also aware of the numpy view method that allows me to see the float as an integer and thus as a binary string: >>> import numpy as np >>>

Extracting floating-point significand and exponent in NumPy

你离开我真会死。 提交于 2020-01-02 23:21:12
问题 I would like to be able to extract the significand and exponent of floating-point numbers in NumPy. Getting the exponent as an integer is fine and ok for the significand. Getting the significand as a bitfield would be even more convienient. I am aware that Python floats have a hex method; however, I wish to use numpy.float32 , numpy arrays, and ufuncs. I am also aware of the numpy view method that allows me to see the float as an integer and thus as a binary string: >>> import numpy as np >>>