math

Regex for math expression

梦想的初衷 提交于 2020-02-07 11:54:29
问题 I have some issue with C++ regex, and hope someone could offer some help. :) Currently, base on the "rxAssign" as shown below, I am able to detect math expression that look like: x = x; x = a + 3 * 90 - b; x = 4; } x = a + 3 * 90 - b; }} However, I need some changes to be able to accept open round bracket "(" and close round bracket ")" for math expression such as: x = (x); x = a + ((3 * 90) - b); x = 4; } x = (((a + 3) * 90) - b); }} Is there anyway I can edit my current implementation to

Perform consecutive checks

北慕城南 提交于 2020-02-06 15:47:32
问题 I have to perform logic if a number is x times bigger than another number. // The distance between two candles var distance = Math.Abs(firstAggregationUpperValue - currentCandleUpperValue); // How many times is the distance bigger than firstAggregationDifference var times = distance / firstAggregationDifference; I have to perform the following checks for times : 7 or above and below 9 (times >= 7 && times < 9) 9 or above and below 12 (times >= 9 && times < 12) 12 or above and below 16 (times

Perform consecutive checks

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-06 15:47:29
问题 I have to perform logic if a number is x times bigger than another number. // The distance between two candles var distance = Math.Abs(firstAggregationUpperValue - currentCandleUpperValue); // How many times is the distance bigger than firstAggregationDifference var times = distance / firstAggregationDifference; I have to perform the following checks for times : 7 or above and below 9 (times >= 7 && times < 9) 9 or above and below 12 (times >= 9 && times < 12) 12 or above and below 16 (times

Is there a way to encode any number into a series of 8-bit numbers, including a terminating character?

折月煮酒 提交于 2020-02-06 09:07:52
问题 So I would like to encode numbers as small as 0 and as high as very high (32-bit, 64-bit, other 8-bit multiples...). The simple approach is to just use the computer architecture's built-in support for "word" size or whatever, so like 32-bit or 64-bit are the common cases, so integers limited to that size. But I would like to do a theoretical thing and see if there is a way to encode arbitrarily large numbers using a sequence of 8-bit numbers. But then as a caveat, I want to know when we've

PDO count row values based on WHERE

≯℡__Kan透↙ 提交于 2020-02-06 09:07:21
问题 I looked over PHPDelusions website few times before asking this, as well as used Google but I still can't seem to get the code to work, or find a solution that remotely mirrors my question in general. I made a super simple PHP7 script for managing Receipts. The fields are simple. id (int 12), amount (varchar 8), category (int 2), date (date) The problem I'm facing is I'm trying to Count the Total Amount of money based on Categories . So let's say Category = 1 would count all Amounts with that

Literal Int to Double coercion in arithmetic expressions [duplicate]

筅森魡賤 提交于 2020-02-06 09:03:25
问题 This question already has an answer here : Strange Swift numbers type casting (1 answer) Closed 3 months ago . It appears that Swift applies floating point contagion (as it is called in other languages) to literal Int operands in an expression containing a Double variable before evaluating the expression. Is there an explicit statement about that somewhere? I wasn't able to find a specific description about what to expect. For example, suppose I have let b = 0.14 . Then the following all

Convert a list of floats to the nearest whole number if greater than x in Python

烈酒焚心 提交于 2020-02-05 11:15:50
问题 I'm new to Python and I did my research but didn't get far, hence the post for help. I have a list of floats which I would like to round to the nearest whole number ONLY if the element is greater than 0.50. list = [54.12,86.22,0.30,0.90,0.80,14.33,0.20] expected outcome: list = [54,86,0.30,1,1,14,0.20] 回答1: use the python conditional expression: [round(x) if x > 0.5 else x for x in lst] e.g.: >>> [round(x) if x > 0.5 else x for x in lst] [54.0, 86.0, 0.3, 1.0, 1.0, 14.0, 0.2] To get it

drawing points evenly distributed on a circle

对着背影说爱祢 提交于 2020-02-05 10:17:28
问题 i want to get the coordinates of n points on a circle with the diameter of x i tried this: <?php header("Content-Type: image/png"); $img = @imagecreate(900, 900) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($img, 255, 255, 255); $red = imagecolorallocate($img, 255, 0, 0); for($i=0;$i<=360;$i+=10) { $x = round(cos($i)*400)+450; $y = round(sin($i)*400)+450; imagefilledellipse($img, $x, $y, 3, 3, $red); } imagepng($img); imagedestroy($img); ?> but there

Integration via trapezoidal sums in MATLAB

浪尽此生 提交于 2020-02-05 08:23:49
问题 I need help finding an integral of a function using trapezoidal sums. The program should take successive trapezoidal sums with n = 1, 2, 3, ... subintervals until there are two neighouring values of n that differ by less than a given tolerance. I want at least one FOR loop within a WHILE loop and I don't want to use the trapz function. The program takes four inputs: f : A function handle for a function of x . a : A real number. b : A real number larger than a . tolerance : A real number that

Finding points of intersection when two spheres intersect

老子叫甜甜 提交于 2020-02-05 07:39:20
问题 I have the center (xyz - in 3 dimensional space) and the radius of two spheres A and B. Now I have to figure out a point or more than 1 point where these spheres meet. It is fairly easy to figure out if the two spheres collide or not, but how do I find out the points of intersection of 2 spheres? Any help would be greatly appreciated. 回答1: The curve where they intersect is a circle. The equation for the radius of the circle is a bit complicated, but is shown here, in eqn. 8, and this distance