math

Continuous Fractions

醉酒当歌 提交于 2020-01-15 06:53:11
问题 My understanding of continuous fractions was that it will always give a representation of a decimal in fraction form. I thought that continuous fraction would always return value less than or equal to the decimal number. Unfortunately my code occasionally returns fractional values greater than the decimal input. Is my understanding of continuous fractions correct? If so can you please explain where in my code the error lies. public static Rational contFrac(double a, int i,int n){ if(i<n){

Incrementing array values - Arduino

早过忘川 提交于 2020-01-15 06:43:49
问题 I'm trying to increment some array values: int counter[] = {0,0,0,0,0,0,0,0}; If the value of the number in position 0 reaches 25, then the value in position 1 is incremented by 1, and position 0 reset to 0. And so on - when index position 2 reaches 25 it increments position 3 by 1, and resets it's own value to 0. I'm doing some base26 incrementing - generating all the combinations of letters for a given number of letters. Ideally I'd like this to work infinitely (in theory) - a new array

Figure out what keys a player is pressing based on relative velocity and angle

你离开我真会死。 提交于 2020-01-15 03:39:06
问题 I have two pieces of information: a 2D-vector representing velocity relative to a grid and an angle (180 to negative 180 degrees) representing the player's view-angle also relative to that grid, and I am from that trying to figure out what keys (W, A, S, D) the player is pressing with this information. The thing that is giving me troubles are the fact that the player moves in respect to the view-angle. So if the player is looking 35 degrees relative to our grid and pressing forward (W), the

Functions to Round up and Round down fractions with precision in PHP, any better way to do it?

a 夏天 提交于 2020-01-15 03:14:25
问题 I found this code on php.net which works for me for the round_up part.. function round_up($value, $precision = 0) { if (!empty($value)) { $sign = (0 <= $value) ? +1 : -1; $amt = explode('.', $value); $precision = (int) $precision; if (strlen($amt[1]) > $precision) { $next = (int) substr($amt[1], $precision); $amt[1] = (float) (('.'.substr($amt[1], 0, $precision)) * $sign); if (0 != $next) { if (+1 == $sign) { $amt[1] = $amt[1] + (float) (('.'.str_repeat('0', $precision - 1).'1') * $sign); } }

Why does my recursive factorial method always return 0? [duplicate]

烈酒焚心 提交于 2020-01-15 03:11:33
问题 This question already has answers here : Why does Java think that the product of all numbers from 10 to 99 is 0? (9 answers) Closed 4 years ago . I have created a recursive method to calculate the facortial of a number, however, it is always returning 0, and I can not see why. I have provided my code below: public class projectTwenty { public static void main(String [] args) { int factorialAns = factorial(100); System.out.println(factorialAns); } private static int factorial(int n) { if (n ==

Evaluating 3d splines exported from max in a C++ program

与世无争的帅哥 提交于 2020-01-14 14:54:31
问题 My C++ program requires access to 3D splines that have been constructed in 3ds Max (2011). I have found a simple maxscript that exports these splines as XML files - an example as follows: <spline name='Line001' knots='5' closed='true'> <knot x='-4.67297e-005' y='0.0' z='0.0'> <invec x='-0.000144482' y='-600.0' z='-1.52588e-005' /> <outvec x='5.10227e-005' y='600.0' z='1.52588e-005' /> </knot> <knot x='6.17511e-005' y='800.0' z='500.0'> <invec x='7.92357e-005' y='800.0' z='100.0' /> <outvec x=

d3.js moving average with previous and next data values

与世无争的帅哥 提交于 2020-01-14 14:32:07
问题 I'm new to D3 and trying to do a moving average of previous and next values on my data in order to smooth it out. Currently, I have it working using the 2 previous values + the current value. It does work but 1) how would I also use the next values, and 2) what if I wanted to use the 15 previous and 15 next values? (it would be crazy to have 30 individual vars for storing all of them) I'm used to traditional javascript but lost as to how to traverse the data this way in D3. Hope someone can

Problems rendering a Polar Zonohedron in Processing

余生颓废 提交于 2020-01-14 14:13:33
问题 I've recently been looking into Zonohedrons and Rob Bell made beautiful ones. I had a play with the free Polar Zonohedron Sketchup Plugin and thought about playing with the geometry using Processing. So far I've open up the plugin/Ruby script and tried to port it directly, but I am not experienced with Ruby and have been using the Sketchup Ruby API reference. The geometry part of the code is mostly in the polar_zonohedron function: def polar_zonohedron #frequency, pitch = atan(sqrt(2)/2), len

How does Javascript handle BODMAS?

戏子无情 提交于 2020-01-14 13:44:08
问题 I've been doing a bit of math with Javascript for a project I'm currently working on, and have just stumbled across the following: I'm calculating an amount of results remaining in a list of results (there's a "Load More" button) The code is as follows: if (data.length > startIndex + maxLoadAmount) { var loadMoreButton = new LoadButton() loadButton.ToLoad = data.length - startIndex + maxLoadAmount; loadMoreButton.click(function () { var amountOfCurrentWidgets = $(this).parent().children('

How does Javascript handle BODMAS?

試著忘記壹切 提交于 2020-01-14 13:44:05
问题 I've been doing a bit of math with Javascript for a project I'm currently working on, and have just stumbled across the following: I'm calculating an amount of results remaining in a list of results (there's a "Load More" button) The code is as follows: if (data.length > startIndex + maxLoadAmount) { var loadMoreButton = new LoadButton() loadButton.ToLoad = data.length - startIndex + maxLoadAmount; loadMoreButton.click(function () { var amountOfCurrentWidgets = $(this).parent().children('