46,054 questions
Advice
1
vote
6
replies
118
views
Why does JavaScript’s Math.round(-1.5) round toward positive infinity instead of following standard rounding?
If we round a negative number to the nearest integer in JavaScript, in the case of a tie (i.e., a fractional part of 0.5), the nearest integer is the one closer to positive infinity. For example: Math....
1
vote
2
answers
83
views
Correctness of Algorithm: Convert Sorted Array to Height Balanced BST
I was working on Leetocde 108: Convert Sorted Array to Binary Search Tree.
The input is a sorted array of integers, and the goal is to return a height-balanced binary search tree (BST), meaning that ...
0
votes
1
answer
114
views
How can I connect the smooth curve edges of this Shape in SwiftUI?
I have this Wavy Stamp Shape
struct WavyPostageStampShape: Shape {
var amplitude: CGFloat = 8
var wavesX: Int = 6
var wavesY: Int = 10
var phase: CGFloat = 0
var step: CGFloat = 2
...
Tooling
1
vote
2
replies
138
views
How to calculate the area of irregular shapes programmatically?
I’m working on calculating the area of irregular shapes (such as polygons with uneven or non-parallel sides) in code.
I understand how to calculate areas for regular shapes, but I’m unsure what the ...
Advice
1
vote
9
replies
76
views
How to model shared geometric objects (points, rays, lines) without duplication in Python?
I'm working on a small Python prototype to model basic Euclidean geometry objects (lines, rays, points). I've intentionally stripped it down to a minimal example to highlight a design issue I'm ...
-1
votes
2
answers
67
views
I want to click a button in Google sheets that will increment cells that have a number by +1 each time it's pressed [closed]
I don't know how to script or add scripts in Google sheets android
When something is pressed, check of cell contains a number AND is NOT empty. add +1 to cell. Allow this to happen to multiple cells ...
1
vote
2
answers
203
views
How can I programmatically derive Taylor series?
So I know from physics that position at a given time can be calculated using its derivatives like this:
Now I know this looks awfully similar to Taylor series:
In fact they are exactly the same. ...
Best practices
2
votes
3
replies
90
views
How do you calculate a row of Pascal's triangle, mod 10, in linear time?
I would prefer to do this without having to calculate every previous row of Pascal's triangle first. I'm familiar with the algorithm for calculating the nth row of Pascal's triangle directly, where ...
1
vote
3
answers
238
views
How can I make my tangent numbers generating class resumable?
I have decided to implement code to generate tangent numbers as a self-imposed programming challenge. I have succeeded in doing so, but not as efficient as I want it to be.
What are tangent numbers? ...
Advice
1
vote
5
replies
92
views
How to compare 3d directions as equidistant on both diagonal and horizontal/vertical
I'm currently using Unity (and C#) in a direction comparison system I'm currently making. For a cut down example, these are some directions I have:
{Up, {0,1,0}}, {UpRight, {1,1,0}}, {UpRightForward, {...
Best practices
0
votes
3
replies
41
views
How does spectral centroid behave? (breaking-wave / bubble noise)
I’m working on an underwater acoustics project (student project) analyzing the sound of breaking waves. When a wave breaks, bubbles are entrained and their oscillations generate broadband underwater ...
Best practices
0
votes
2
replies
85
views
how to calculate result of calculator in dart , button equal?
I am trying to build function for calculator
this is my code :
ExpressionParser p = GrammarParser();
Expression exp = p.parse(input);
var evaluator = ...
Advice
1
vote
2
replies
70
views
Optimizing Node.js worker threads memory pooling for heavy Monte Carlo slot simulations (RTP verification)
I'm developing the math engine for a high-volatility cascading slot game (similar to Megaways mechanics). As part of our global compliance and certification process, we need to run Monte Carlo ...
Advice
2
votes
11
replies
94
views
Python algorithm to automatically propagate inequalities transitively
I am trying to build a Python algorithm that can transitively propagate inequalities between objects. For example, if I know that A < B and B < C, I want the system to automatically infer that A ...
3
votes
0
answers
155
views
Transform points from one coordinate system into another, given only two poses
I know, this should be easy to solve, but I have been struggling with it for a few days and have not been able to find the problem.
I have given two poses of the same object in two different ...
0
votes
3
answers
175
views
How to systematise a checking of "a quite equals to b" (either with round method or | a - b | ~ 0) for any value of a?
My context
I have implemented an equals(Object o) method for a speed object (Vitesse here) that when it faces a comparand being in m/s when it is itself in km/h (in example) puts the comparand in km/h ...
0
votes
1
answer
159
views
How to calculate the points on the "perimeter" on a bitmask?
I am making a drawing application and i have to show the borders of the pencil. To know where to place the pixels I use a list of integer offsets from the cursor that make up a shape, so the cursor is ...
0
votes
2
answers
84
views
Removing Transforms manually from SVG
I want to get rid of transforms in my SVG, for more simplicity in dealing with my already complex shapes and code. I manipulate the inline SVG dynamically on my web site in PHP.
Transforms has four ...
Advice
0
votes
5
replies
104
views
Converting latitude and longitude from degrees to meters
As the title says, how can i convert a value that i have from a longitude or latitude from degrees to meters ? The task is basically to calculate MAE errors for x,y,z of trajectory prediction, MAE Z ...
Advice
2
votes
10
replies
71
views
How to fit a circle onto a weathered pipe?
I have a 3d scan of a metal pipe and I can slice it at different heights. When looking at a cross-section of a new pipe, the data should match the shape of a perfect circle, but due to erosion the ...
1
vote
1
answer
187
views
How flash 8 brush worked?
I'll be questioning about a drawing program - flash 8 and how its brush worked.
The question is about math, bezier curves, vectors, algoritms, geometry.
i'm trying to recreate how Flash 8's brush tool ...
-2
votes
1
answer
306
views
Self-recursing-iterative functions in Python
I was writing an implementation of the Knuth up-arrow notation, and I realized I had a problem. To make it work, I would have to iteratively stack more and more references to a function containing my &...
6
votes
1
answer
786
views
Code is not generating concentric circles
I am drawing some 2D renders, and I tried to render the cosine of the distance as a color. What I expected was some concentric circles with the color oscillating once, but this does not do that.
...
5
votes
2
answers
162
views
Unique combinations preserving order
I have a list of elements like [1, 1, 2, 2, 3, 4, 5]. I want to iterate through all the k-length sub-lists of this list, such that identical combinations do not occur, that is I don't get [1, 3, 4] ...
Advice
0
votes
7
replies
152
views
How to calculate a logarithm quickly; bit width of the answer is more important than the base
There are many Stack Overflow questions about fast logarithm calculation, but all of them presuppose that you want to calculate a logarithm using a specific base. Two, e, and 10 are popular bases.
I ...
0
votes
2
answers
88
views
Math CAPTCHA don't work with dividing - how to fix? [closed]
I’m writing a Selenium script to auto-fill a contact form, like this one, and yeah, obviously the main site is different — cornerstonesalina.com/elements/contact-form/, there’s a math captcha like &...
0
votes
1
answer
99
views
Excel Formula - Calculate cost using height and width of glass in mm based on (minimum sqm cost value £270)
I am trying to use an Excel Formula to calculate the cost using the height and width of glass in millimeters, dividing the result by 1000 and then multiplying it by the minimum square meter cost value ...
Advice
0
votes
3
replies
155
views
Excel - Mathematical calculations: how to find the best matching volume?
I have one worksheet with a few columns:
Product name
part name
order of part in product
Volume A
Volume B
Difference vol A and B
Dif %
One part can be used for many products. All products are ...
0
votes
1
answer
135
views
DAX Query Filtering
I have one table(final Table) which has columns (date, volume, Month, resource) where I'm calculating the utilization of a resource. so,I need to have time which gets calculated as per below formula ...
2
votes
1
answer
100
views
NumPy generate a 2d linear array using multiple values
So I'm trying to generate a map for a personal project using opensimplex noise, multiple layers etc.
My problem is that I want to recreate the equator to combine with a temperature map to obviously ...
3
votes
2
answers
269
views
diverging std::atan2's unit of least precision
I write a cross-platform program for Windows and Linux, and I would like it to behave as similar on both platforms as possible. I use some mathematics in the program, e.g. std::atan2 function calls, ...
2
votes
1
answer
146
views
What does <string>:2(__init__) have to do with mathematical computations?
I'm in the process of writing some mathematical operations. Here's a sample program to give you an idea of what kind of thing I could be doing:
from dataclasses import dataclass
import random
@...
Advice
1
vote
2
replies
117
views
Math for incrementing a counter for a very large progress bar where total doesn't fit in an int
There is a progress indicator with 100 steps. However, the total number of items being processed is much too large; it doesn't fit in a register. Thus, the simple way of V = (P * 100) / T is ...
Advice
2
votes
3
replies
135
views
Reverse-engineering CRC checksum algorithm from an oracle
I have an embedded device that implements an unknown 32-bit CRC-based checksum algorithm in hardware. I can use this device as an oracle to generate checksum values from arbitrary input, and verify ...
Best practices
3
votes
6
replies
154
views
Avoiding array duplication in big integer routine
I am working on a multiplication routine in a big integer library in POSIX C99 with a signature of bigint_st *bigint_mul(bigint_st *dest, const bigint_st *a, const bigint_st *b). Many of the routines ...
Advice
0
votes
4
replies
66
views
Intentionally Constructing Hash Collisions
I want a simple hashing algorithm with the following conditions:
1,) if n is a ten-digit integer, eg, 1234567890, then the hash of n will equal the hash of all (left-justified) sub-strings of n. As in,...
4
votes
1
answer
283
views
Accurate computation of the inverse gamma function with the standard C math library
The inverse of the gamma function over the reals is multivalued with an infinite number of branches. This self-answered question is about the principal
inverse of the gamma function, Γ0-1(x), whose ...
Advice
0
votes
1
replies
99
views
Generating SageMath codes to solve this elliptic curve equation
I was working on this elliptic curve equation: y^2 = x^3 - 228n*x - (432n^6 - 1368n^3 - 361) and using SageMath, I have been able to develop rational points for the cases n = 1, 3 and 4. For the case ...
Advice
0
votes
13
replies
6k
views
Which algorithm does the truncate function use in c++
I'm wondering how the truncate function works. C++ is just an example i'm using because it's a language I know. I've searched online and I can't seem to find how it works, simply how to use it and ...
Advice
0
votes
1
replies
301
views
How to properly change the font family of KaTeX math text that also looks nice on stretched/large glyphs?
I was asking ChatGPT about how to take a custom-designed monospaced font, and specifically how to make the "stretchy math glyphs/constructs" (parentheses, brackets, braces, integrals, ...
Advice
1
vote
9
replies
136
views
Sum of a binary tree
I have a binary tree which leafs have a size of 1, and the parent double in size at each level.
I project those nodes on a linear axe (memory space).
I need to get the equation that gives the adress ...
10
votes
3
answers
643
views
Finding a maximum "score" of a permutation
Consider an array of a permutation P of length n (n > 2), namely some order of the integers 1 through n.
Example of P with length n = 7,
[6,5,2,3,7,1,4]
A "score" of a permutation is ...
-3
votes
1
answer
72
views
Auto converting typed math to Latex/Mathjax [closed]
I use a learning management system from my coaching classes, and due to copyrighted material, I can't share screenshots here. However, I'm attempting to convert typed math to Latex/Mathjax math ...
0
votes
2
answers
124
views
Weighted percentages
I have a problem on how to calculate "partial" percentages that match the "total" percentage.
My problem is as in the table below.
I have values for the beginning and end of the ...
1
vote
0
answers
94
views
QEF Implementation returns unexpected results on the Z value
I have a QEF implementation like this
float atA[3][3] = { 0 };
FVector atb = FVector::ZeroVector;
for (const FEdgeIntersection& e : IntersectionList)
{
const FVector& n = e.Normal;
...
1
vote
2
answers
125
views
How do I remap the output of an SVG <feTurbulence> filter's Alpha channel to span the entire range of brightness values?
I know I can create a clean grayscale fog effect by applying an <feColorMatrix> effect to the output of an <feTurbulence> effect in order to isolate the Alpha channel:
<?xml version="1....
2
votes
0
answers
70
views
Having problems computing PDE Residuals
I'm computing PDE residuals for The_Well datasets (e.g. turbulent_radiative_layer_2D and shear_flow) using finite differences, but the residuals are much larger than I expect. The data are generated ...
-2
votes
1
answer
116
views
Algorithm to calculate how much blend of points is a specific 2D point [closed]
I have a Set of 2D points that I want to create a set of areas from, similar to a Voronoi Diagram.
The difference is that I would like these areas to be blended, like in the following image.
I wouldn'...
1
vote
3
answers
264
views
Wrong result when adding up to result in my number conversion program [duplicate]
I am currently writing a program in C to convert numbers between bases as an exercise. It asks the user for an input and for the base, that the number given is. It then gives the input into the ...
14
votes
4
answers
2k
views
Estimation for Pi is precise but inaccurate
My code reliably finds a precise (similar value every time) but in the region of 3.24 and 3.26. Competent mathematicians will note this around 0.1 away from an ideal Pi value.
My code revolves around ...