How can I convert a short [] to a duplicate []?

Now, I'm working one audio signal processing, and I want to do a real time display audio sound wave which I recorded by my phone. Here is a problem that my audio format is "ENCODING_PCM_16BIT". So how can I change 16bit short data to double form

Can I print -0.000 as 0.000?

printf("%.3lf\n", -0.0001); This outputs -0.000, but shouldn't it be 0.000? How can I make this print without the minus sign, i.e. 0.000 ?The correct answer has already been given. Just wanted to add that you'll get the same from c++ cout If you

How to dynamically add to double []?

How to dynamically add to double[]? Should I create a List... List<double[]> y = new ArrayList<double[]>(); y.add(new double[15]); y.add(new double[20]); and convert List to double[]?use a List<Double> such as List<Doulble> list =

Shorten the double value x digit

I have a double value and I want to shorten it to 6 digits after the integer part. For example: double aDouble = 418.73684210526318; double convertedDouble = conversion (aDouble); convertedDouble must be 418.736842 I implemented this solution: conver

How to return the values ​​found in a Java switch statement

How would I return the values that I found in this switch statement to the rest of the class for use (I want to use oneTotal, twoTotal, etc. out side of that switch statement)? Here is the code for the switch statement: switch(itemNo){ case 1: double

Errors multiplying the big doubles

I've made a BOMDAS calculator in C++ that uses doubles. Whenever I input an expression like 1000000000000000000000*1000000000000000000000 I get a result like 1000000000000000000004341624882808674582528.000000. I suspect it has something to do with fl

Allocate a matrix in C using malloc

I wrote a C code that usea a matrix of double: double y[LENGTH][4]; whith LENGTH=200000 I have no problem. I have to increase the numbers of rows to LENGTH=1000000 but when I enter this value and execute the program it returns me segmentation fault.

Problems with a class in Java

public class Location { private String city; private double latitude; private double longitude; public Location(String aCity, double aLatitude, double aLongitude) { city = aCity; latitude = aLatitude; longitude = aLongitude; } void setLocation(String

How do you round this

I'm working on a number converter project on high school, and this is for "length." My two problems are: How do I round off the result to the 0.00 value? How do I make the exception to allow decimal inputs it shows the error message if the numbe

How does ~~ work like math.floor?

This question already has an answer here: What does ~~ ("double tilde") do in Javascript? 9 answers `Math.trunc` vs `|0` vs `<<0` vs `>>0` vs `&-1` vs `^0` 2 answers I understand that ~ is a bitwise NOT operator, but how does inv

Printf print C ++ double reads like 0

So I want to use printf so that I can make columns line up but printf can't seem to print doubles that need scientific notation. It just comes out as a 0 but with cout it comes out fine. 'in' and 'fn' are structs 'x' 'y' and 'z' are doubles Code prin

Why is the float double, imprecise, double so as not to float?

I know that floating point variables loose precision while casting. But what I don't understand is, why a cast from a smaller primitive to a bigger one is unprecise but vice versa not. I would understand if it happens from double to float but it's th

Double C ++ conversion string using atof

I cannot get the atof() function to work. I only want the user to input values (in the form of decimal numbers) until they enter '|' and it to then break out the loop. I want the values to initially be read in as strings and then converted to doubles

Randomize when something happens

I have implemented a power up in my game and I want it to have an 10% chance to apply to the player when it kills a zombie. I have tried using this code every time the players bullet hits an zombie, but it doesn't really work. double rand = Math.rand

The most effective way to multiply a double by 2?

Let's say we have a boxed double variable, foo and we want to multiply its value by 2 and store it in another boxed double variable , bar. From the following approaches, Approach One: Double bar = foo * 2; and, Approach Two: Double bar = Double.value

Double Java does not calculate correctly

I'm making this program for a class and I need to guess a number's cube root. Here's my code: int N = Integer.parseInt(args[0]); //sets the guess at 1.0 guess = 1.0; //whether or not the guess is close to N while (guess * guess * guess <= N ){ double

Java: Fast Double to the Euro String Representation

I needed to display a lot of currency (euro) values, which all may change while using a slider. Therefore, I created a faster Double to Euro function instead of using a number formatter (no internalization needed, runs on an android device with limit

Can not add / subtract large doubles in goal C

I am trying to subtract 1 from a double with this code: -(NSMutableArray *)getMoreTwitterDataWithMaxID:(double)maxID { double newestID = (maxID - 1); NSLog(@"newest ID is %f and maxID is %f", newestID, maxID); // other code } The console is spit

How to limit the number of printed decimals for a double?

This program works, except when the number of nJars is a multiple of 7, I will get an answer like $14.999999999999998. For 6, the output is 14.08. How do I fix exceptions for multiples of 7 so it will display something like $14.99? import java.util.S

C ++% overload operator for two doubles

is it possible to overload the operator% for two doubles? const double operator%(const double& lhs, const double& rhs) { return fmod(lhs, rhs); } Of course, this generates an error because one of the two parameters must have a class type. So I tho

only 6 decimals for the double

I think this is a dumb question. but i cannot figure it out. Please don't shoot me. :P I want to get double value like 8.000000111333. but I can only get up to 6 decimal places. for instance double _result = 8.000000111333; DLog(@"%f", _result);

How to sort a list & lt; T & gt; by double value?

This sound simple but it not that much. I want to order a List based on one of the properties of T, which is double type.If you know the propertyname before compilation: myList = myList.OrderBy(a=>a.propertyName).ToList(); or myList = (from m in myLi

floating point accuracy

I have a program written in C# and some parts are writing in native C/C++. I use doubles to calculate some values and sometimes the result is wrong because of too small precision. After some investigation i figured out that someone is setting the flo