numerical

How do I save a floating-point number in 2 bytes?

别来无恙 提交于 2019-12-01 05:26:05
Yes I'm aware of the IEEE-754 half-precision standard, and yes I'm aware of the work done in the field. Put very simply, I'm trying to save a simple floating point number (like 52.1 , or 1.25 ) in just 2 bytes. I've tried some implementations in Java and in C# but they ruin the input value by decoding a different number. You feed in 32.1 and after encode-decode you get 32.0985 . Is there ANY way I can store floating point numbers in just 16-bits without ruining the input value? Thanks very much. You could store three digits in BCD and use the remaining four bits for the decimal point position:

What is the range for Arabic-Indic Digits (Hindu–Arabic) numeral utf8 from 0 to 9

六眼飞鱼酱① 提交于 2019-12-01 02:00:39
What is the range for Arabic-Indic Digits (Hindu–Arabic) numeral utf8 from 0 to 9 for the use in regular expressions: to use in regex. U+06F0–U+06F9. As can be easily seen when checking a Unicode code point chart or the Character Map. finally I found the answer for only numbers: \x{0660}-\x{0669} for numbers and letters: \x{0600}-\x{06ff} Unicode 4.0 / ISO 10646 Plane 0 thanks you all. 来源: https://stackoverflow.com/questions/14834846/what-is-the-range-for-arabic-indic-digits-hindu-arabic-numeral-utf8-from-0-to

Accept Numerical Values only for input using scanf

*爱你&永不变心* 提交于 2019-11-30 23:31:53
How can I make sure the user inputs numerical values only instead of alphanumeric or any other character? Also what to look for to insert error message for incorrent input? #include<stdio.h> int main() { int a, b, c; printf("Enter first number to add\n"); scanf("%d",&a); printf("Enter second number to add\n"); scanf("%d",&b); c = a + b; printf("Sum of entered numbers = %d\n",c); return 0; } If you really want to deal with user input that could be hostile use a separate function for getting the number. Allows - leading spaces : " 123" - trailing spaces : "123 " - leading zeros :

Finding the “discrete” difference between close floating point numbers

孤街醉人 提交于 2019-11-30 23:02:23
Suppose I have two floating point numbers, x and y , with their values being very close. There's a discrete number of floating point numbers representable on a computer, so we can enumerate them in increasing order: f_1, f_2, f_3, ... . I wish to find the distance of x and y in this list (i.e. are they 1, 2, 3, ... or n discrete steps apart?) Is it possible to do this by only using arithmetic operations ( +-*/ ), and not looking at the binary representation? I'm primarily interested in how this works on x86. Is the following approximation correct, assuming that y > x and that x and y are only

How to compute an exponent in matlab without getting inf?

女生的网名这么多〃 提交于 2019-11-30 22:15:06
The title says it all: I want to calculate an exponent in matlab with big numbers, but I get overflow and it just returns infinity. >> 100^1000 ans = Inf Last time I checked, 100^1000 is decidedly smaller than infinity :) As Daniel has already pointed out, it's too big a number to be even outputted by MATLAB itself. This number is obtained with realmax for different datatypes. As an alternative to represent/use such huge numbers, you can use the corresponding mantissa and exponent with base-10 representation instead, which is the usual MATLAB representation. The function to get those two is

Explicit integral could not be found

不想你离开。 提交于 2019-11-30 19:10:19
问题 I am getting a well-known error of "Explicit integral could not be found" if I try to evaluate following integral syms z; funz=1./(1+exp((z*z-0.5)/0.1)); Integ2=int(funz,z,0,inf) I get the warning: Warning: Explicit integral could not be found. Integ2 = int(1/(exp(10*z^2 - 5) + 1), z == 0..Inf) Mathematica evaluates this integral to 0.693 . I have tried replacing lower integration limit to some small finite number (0.001) but that doesn't help. Please help in identifying the fix for this

Finding the “discrete” difference between close floating point numbers

孤人 提交于 2019-11-30 18:17:20
问题 Suppose I have two floating point numbers, x and y , with their values being very close. There's a discrete number of floating point numbers representable on a computer, so we can enumerate them in increasing order: f_1, f_2, f_3, ... . I wish to find the distance of x and y in this list (i.e. are they 1, 2, 3, ... or n discrete steps apart?) Is it possible to do this by only using arithmetic operations ( +-*/ ), and not looking at the binary representation? I'm primarily interested in how

Numerical integration in C++

岁酱吖の 提交于 2019-11-30 15:22:46
I need to integrate a function (of two variables). I know I can do it by using Fubini theorem to integrate one variable functions, then using numerical methods such as the Rectangle method or the Trapezoidal rule . But are there any pre-built functions to do that in C++ ? I need to integrate over the unit R2 triangle ((0,0), (1,0), (0,1)) . Wagner Patriota You can use the GNU Scientific Library , which supports many "Numerical analysis" functions including integration. A very simple example of integration from the manual is just a few lines of code: #include <stdio.h> #include <math.h>

Derivatives in C/C++?

本小妞迷上赌 提交于 2019-11-30 12:37:03
问题 I have some expressions such as x^2+y^2 that I'd like to use for some math calculations. One of the things I'd like to do is to take partial derivatives of the expressions. So if f(x,y) = x^2 + y^2 then the partial of f with respect to x would be 2x , the partial with respect to y would be 2y . I wrote a dinky function using a finite differences method but I'm running into lots of problems with floating point precision. For example, I end up with 1.99234 instead of 2 . Are there any libraries

How to compute an exponent in matlab without getting inf?

天大地大妈咪最大 提交于 2019-11-30 05:42:42
问题 The title says it all: I want to calculate an exponent in matlab with big numbers, but I get overflow and it just returns infinity. >> 100^1000 ans = Inf Last time I checked, 100^1000 is decidedly smaller than infinity :) 回答1: As Daniel has already pointed out, it's too big a number to be even outputted by MATLAB itself. This number is obtained with realmax for different datatypes. As an alternative to represent/use such huge numbers, you can use the corresponding mantissa and exponent with