Search Results

Search found 6319 results on 253 pages for 'double buffering'.

Page 3/253 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • How to read in a negative double with scanf() in C

    - by rize
    I'm learning basics of C and writing a simple first order equation solver. I want the input to be exactly ax+b=c or ax-b=c, where a, b, c are double type. I'm employing scanf() to read in user input and to check if it's of the correct form. However, if I enter a negative double, -4.6 say, as the "a" in the equation, scanf() won't read the a,b,c correctly. I'm using %lf inside scanf(). How do I read a negative double, then? Many thanks. My code: if (scanf("%lfx+%lf=%lf", &a, &b, &c)) more code If I use as the input "-6.2x+3.4=-5.9", the value 3.4 will be assinged to variable a, while b and c remain as they were and "more code" is run.

    Read the article

  • How to store double using SharedPrefrences?

    - by user3924167
    I am having trouble storing a double in the phone's memory. What are my other options if this isnt possible. Basically what the code is aiming to do using sharedprefrences is take the stored value of "Alcohol" spending and then add whatever the input is in the editText to it and then store that new value for the next time. Running total of spending on alcohol **Can someone please help with this issue and be detailed where x y & z should go in the project. The user selects from a spinner, which works. public void addInput(){ double dblCostInput = Double.valueOf(inputBox.getText().toString()); String strCategories= spinnerCategories.getSelectedItem().toString(); if(strCategories.equals("Alcohol")) { alcoholSpend = alcoholSpend + dblCostInput; inputBox.setText(""); nextInput(); inputBox.setText("Your Spending on"+strCategories+" is: " +d.format(alcoholSpend)); }

    Read the article

  • Segmentation fault in my C program

    - by user233542
    I don't understand why this would give me a seg fault. Any ideas? This is the function that returns the signal to stop the program (plus the other function that is called within this): double bisect(double A0,double A1,double Sol[N],double tol,double c) { double Amid,shot; while (A1-A0 > tol) { Amid = 0.5*(A0+A1); shot = shoot(Sol, Amid, c); if (shot==2.*Pi) { return Amid; } if (shot > 2.*Pi){ A1 = Amid; } else if (shot < 2.*Pi){ A0 = Amid; } } return 0.5*(A1+A0); } double shoot(double Sol[N],double A,double c) { int i,j; /*Initial Conditions*/ for (i=0;i<buff;i++) { Sol[i] = 0.; } for (i=buff+l;i<N;i++) { Sol[i] = 2.*Pi; } Sol[buff]= 0; Sol[buff+1]= A*exp(sqrt(1+3*c)*dx); for (i=buff+2;i<buff+l;i++) { Sol[i] = (dx*dx)*( sin(Sol[i-1]) + c*sin(3.*(Sol[i-1])) ) - Sol[i-2] + 2.*Sol[i-1]; } return Sol[i-1]; } The values buff, l, N are defined using a #define statement. l = 401, buff = 50, N = 2000 Here is the full code: #include <stdio.h> #include <stdlib.h> #include <math.h> #define w 10 /*characteristic width of a soliton*/ #define dx 0.05 /*distance between lattice sites*/ #define s (2*w)/dx /*size of soliton shape*/ #define l (int)(s+1) /*array length for soliton*/ #define N (int)2000 /*length of field array--lattice sites*/ #define Pi (double)4*atan(1) #define buff (int)50 double shoot(double Sol[N],double A,double c); double bisect(double A0,double A1,double Sol[N],double tol,double c); void super_pos(double antiSol[N],double Sol[N],double phi[][N]); void vel_ver(double phi[][N],double v,double c,int tsteps,double dt); int main(int argc, char **argv) { double c,Sol[N],antiSol[N],A,A0,A1,tol,v,dt; int tsteps,i; FILE *fp1,*fp2,*fp3; fp1 = fopen("soliton.dat","w"); fp2 = fopen("final-phi.dat","w"); fp3 = fopen("energy.dat","w"); printf("Please input the number of time steps:"); scanf("%d",&tsteps); printf("Also, enter the time step size:"); scanf("%lf",&dt); do{ printf("Please input the parameter c in the interval [-1/3,1]:"); scanf("%lf",&c);} while(c < (-1./3.) || c > 1.); printf("Please input the inital speed of eiter soliton:"); scanf("%lf",&v); double phi[tsteps+1][N]; tol = 0.0000001; A0 = 0.; A1 = 2.*Pi; A = bisect(A0,A1,Sol,tol,c); shoot(Sol,A,c); for (i=0;i<N;i++) { fprintf(fp1,"%d\t",i); fprintf(fp1,"%lf\n",Sol[i]); } fclose(fp1); super_pos(antiSol,Sol,phi); /*vel_ver(phi,v,c,tsteps,dt); for (i=0;i<N;i++){ fprintf(fp2,"%d\t",i); fprintf(fp2,"%lf\n",phi[tsteps][i]); }*/ } double shoot(double Sol[N],double A,double c) { int i,j; /*Initial Conditions*/ for (i=0;i<buff;i++) { Sol[i] = 0.; } for (i=buff+l;i<N;i++) { Sol[i] = 2.*Pi; } Sol[buff]= 0; Sol[buff+1]= A*exp(sqrt(1+3*c)*dx); for (i=buff+2;i<buff+l;i++) { Sol[i] = (dx*dx)*( sin(Sol[i-1]) + c*sin(3.*(Sol[i-1])) ) - Sol[i-2] + 2.*Sol[i-1]; } return Sol[i-1]; } double bisect(double A0,double A1,double Sol[N],double tol,double c) { double Amid,shot; while (A1-A0 > tol) { Amid = 0.5*(A0+A1); shot = shoot(Sol, Amid, c); if (shot==2.*Pi) { return Amid; } if (shot > 2.*Pi){ A1 = Amid; } else if (shot < 2.*Pi){ A0 = Amid; } } return 0.5*(A1+A0); } void super_pos(double antiSol[N],double Sol[N],double phi[][N]) { int i; /*for (i=0;i<N;i++) { phi[i]=0; } for (i=buffer+s;i<1950-s;i++) { phi[i]=2*Pi; }*/ for (i=0;i<N;i++) { antiSol[i] = Sol[N-i]; } /*for (i=0;i<s+1;i++) { phi[buffer+j] = Sol[j]; phi[1549+j] = antiSol[j]; }*/ for (i=0;i<N;i++) { phi[0][i] = antiSol[i] + Sol[i] - 2.*Pi; } } /* This funciton will set the 2nd input array to the derivative at the time t, for all points x in the lattice */ void deriv2(double phi[][N],double DphiDx2[][N],int t) { //double SolDer2[s+1]; int x; for (x=0;x<N;x++) { DphiDx2[t][x] = (phi[buff+x+1][t] + phi[buff+x-1][t] - 2.*phi[x][t])/(dx*dx); } /*for (i=0;i<N;i++) { ptr[i] = &SolDer2[i]; }*/ //return DphiDx2[x]; } void vel_ver(double phi[][N],double v,double c,int tsteps,double dt) { int t,x; double d1,d2,dp,DphiDx1[tsteps+1][N],DphiDx2[tsteps+1][N],dpdt[tsteps+1][N],p[tsteps+1][N]; for (t=0;t<tsteps;t++){ if (t==0){ for (x=0;x<N;x++){//inital conditions deriv2(phi,DphiDx2,t); dpdt[t][x] = DphiDx2[t][x] - sin(phi[t][x]) - sin(3.*phi[t][x]); DphiDx1[t][x] = (phi[t][x+1] - phi[t][x])/dx; p[t][x] = -v*DphiDx1[t][x]; } } for (x=0;x<N;x++){//velocity-verlet phi[t+1][x] = phi[t][x] + dt*p[t][x] + (dt*dt/2)*dpdt[t][x]; p[t+1][x] = p[t][x] + (dt/2)*dpdt[t][x]; deriv2(phi,DphiDx2,t+1); dpdt[t][x] = DphiDx2[t][x] - sin(phi[t+1][x]) - sin(3.*phi[t+1][x]); p[t+1][x] += (dt/2)*dpdt[t+1][x]; } } } So, this really isn't due to my overwriting the end of the Sol array. I've commented out both functions that I suspected of causing the problem (bisect or shoot) and inserted a print function. Two things happen. When I have code like below: double A,Pi,B,c; c=0; Pi = 4.*atan(1.); A = Pi; B = 1./4.; printf("%lf",B); B = shoot(Sol,A,c); printf("%lf",B); I get a segfault from the function, shoot. However, if I take away the shoot function so that I have: double A,Pi,B,c; c=0; Pi = 4.*atan(1.); A = Pi; B = 1./4.; printf("%lf",B); it gives me a segfault at the printf... Why!?

    Read the article

  • Octave datatypes - float & double

    - by mush
    I'm writing a framework for writing HDF files with JAVA (Using some existing framework). I need to keep compatibility with octave. That is, octave should be able to read the files my framework writes and vice versa. My question is, does Octave have two data types - float and double or it uses only double? thanks

    Read the article

  • Double.TryParse() input decimal separator different than system decimal separator

    - by mare
    I have a source XML that uses a dot (".") as a decimal separator and I am parsing this on a system that uses a comma (",") as a decimal separator. As a result, value of 0.7 gets parsed with Double.TryParse or Double.Parse as 7000000. What are my options to parse correctly? One of them is to replace dots in source with commas with String.Replace('.', ',') but I don't think I like this very much.

    Read the article

  • Python double underscore mangling

    - by gnr
    I am a bit confused by this behavior (using python 3.2): class Bar: pass class Foo: def __init__(self): self.__cache = None bar = Bar() bar.__cache = None foo = Foo() print(vars(bar)) #returns {'__cache': None} print(vars(foo)) #returns {'_Foo__cache': None} I've read up a bit on how double-underscores cause attribute names to be "mangled", but I would have expected the same name-mangling in both cases above. The meaning of a single- and a double-underscore before an object name in Python Any ideas what's going on here?

    Read the article

  • method with two parameters which both need to be double dispatched

    - by mixm
    lets say i have a method which has two parameters. i have been implementing them as: if(aObj instance of Marble) { if(bObj instance of Bomb) { this.resolve((Marble)aObj,(Bomb)bObj); } } as you can see its not a very pretty solution. i plan to implement using double dispatching, but with two parameters which both need double dispatching, im afraid im a bit stumped. any ideas please. im implementing in java btw.

    Read the article

  • GCC problem with raw double type comparisons

    - by Monomer
    I have the following bit of code, however when compiling it with GCC 4.4 with various optimization flags I get some unexpected results when its run. #include <iostream> int main() { const unsigned int cnt = 10; double lst[cnt] = { 0.0 }; const double v[4] = { 131.313, 737.373, 979.797, 731.137 }; for(unsigned int i = 0; i < cnt; ++i) { lst[i] = v[i % 4] * i; } for(unsigned int i = 0; i < cnt; ++i) { double d = v[i % 4] * i; if(lst[i] != d) { std::cout << "error @ : " << i << std::endl; return 1; } } return 0; } when compiled with: "g++ -pedantic -Wall -Werror -O1 -o test test.cpp" I get the following output: "error @ : 3" when compiled with: "g++ -pedantic -Wall -Werror -O2 -o test test.cpp" I get the following output: "error @ : 3" when compiled with: "g++ -pedantic -Wall -Werror -O3 -o test test.cpp" I get no errors when compiled with: "g++ -pedantic -Wall -Werror -o test test.cpp" I get no errors I do not believe this to be an issue related to rounding, or epsilon difference in the comparison. I've tried this with Intel v10 and MSVC 9.0 and they all seem to work as expected. I believe this should be nothing more than a bitwise compare. If I replace the if-statement with the following: if (static_cast<long long int>(lst[i]) != static_cast<long long int>(d)), and add "-Wno-long-long" I get no errors in any of the optimization modes when run. If I add std::cout << d << std::endl; before the "return 1", I get no errors in any of the optimization modes when run. Is this a bug in my code, or is there something wrong with GCC and the way it handles the double type?

    Read the article

  • C int, float, double

    - by anon
    There are certain int values that a float can not represent. However, can a double represent all values a float can represent? (My intuition says yes, since double has more fractional bits & more exponent bits, but there might be some silly gotchas that I'm missing). Thanks!

    Read the article

  • asp.net mvc2 validate type double

    - by ile
    [MetadataType(typeof(Deal_Validation))] public partial class Deal { } public class Deal_Validation { [Required] public string Title { get; set; } public double? EstValue { set; get; } } How to validate EstValue (check if it is of type double?) Thanks

    Read the article

  • Double Buffering in Panda3D (C++)

    - by jsvcycling
    How would I go about using Double Buffering (to create a loading screen) in Panda3D using C++? I've searched Google and found some forums that talk about the concept of swapping buffers, but I haven't seen any that show any type of source code (specifically Panda3D/C++). I'd like to try and stay away from using pure OpenGL code and work it through Panda3D, but if I have no other choice, then I'll have to go with OpenGL coding.

    Read the article

  • Actual long double precision does not agree with std::numeric_limits

    - by dmb
    Working on Mac OS X 10.6.2, Intel, with i686-apple-darwin10-g++-4.2.1, and compiling with the -arch x86_64 flag, I just noticed that while... std::numeric_limits<long double>::max_exponent10 = 4932 ...as is expected, when a long double is actually set to a value with exponent greater than 308, it becomes inf--ie in reality it only has 64bit precision instead of 80bit. Also, sizeof() is showing long doubles to be 16 bytes, which they should be. Finally, using gives the same results as . Does anyone know where the discrepancy might be? long double x = 1e308, y = 1e309; cout << std::numeric_limits::max_exponent10 << endl; cout << x << '\t' << y << endl; cout << sizeof(x) << endl; gives 4932 1e+308 inf 16

    Read the article

  • HTML Double Click Selection Oddity

    - by Aren B
    I didn't post this on DocType because it's not really a design thing, the visual representation isn't my problem, the behaviour is. I'm sorry if this is misplaced but I don't feel it's a designer issue. The following DOM: <ul style="overflow: hidden;"> <li style="float: left;"><strong>SKU:</strong>123123</li> <li style="float: left;"><strong>ILC:</strong>asdasdasdasd</li> </ul> Or <div style="overflow: hidden;"> <div style="float: left; width: 49%"><strong>SKU:</strong>123123</div> <div style="margin-left: 50%; width: auto;"><strong>ILC:</strong>asdasdasdasd</div> </div> Or <p> <span><strong>SKU:</strong>123123</span> <span><strong>ILC:</strong>asdasdasdasd</span> </p> All present me an odd problem in IE 6 IE 7 Firefox 3.x Chrome But not in IE 8 When you double click '123123' after 'SKU:', it selects '123123' AND 'ILC:' from the next dom element. Take any text on this page (here in SO), double click a word, it only selects THAT WORD, even in the middle of a paragraph. These examples have dom elements closing them, anyone know why this is happening. My fellow employees use the 'double click' mechanism to select the relevant product ID's to do their job, and this dosen't make sense to me what soever.

    Read the article

  • How to convert an object into a double?

    - by george t.
    I am working on VS C# on the following code, which converts an user input math expression and computes it. MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl(); sc.Language = "VBScript"; sc.ExecuteStatement( "function pi\n" + "pi = 3.14159265\n" + "end function"); sc.ExecuteStatement( "function e\n" + "e = exp(1)\n" + "end function"); expression = textBox1.Text.ToString(); expression = expression.Replace("x", i.ToString()); object y = sc.Eval(expression); string k = y.ToString(); double result = double.Parse(k); While this outputs onto the console with the correct result, I want to use the values to make a graph of the function user inputs and it's not doing it correctly. Thank you for your help.

    Read the article

  • Fighting Game and input buffering

    - by Pilispring
    In fighting game, there is an important thing called input buffering. When your character is doing an action, you can input the next action that will activate as soon as possible (the buffer is 5-10 frames). Is anyone had already done it or knows the most efficient way to do this? I thought of things like that: Enum list moves (a list of all my moves) if (moves = fireball) { if (Mycharacterisidle) { Do the fireball } else if (MycharacterisMoving) { if (lastspriteisnotfinished) { InputBuffer++; } else if(spriteisfinished && InputBuffer < 5) { Do the fireball } } } Any better ideas? Thx.

    Read the article

  • How to stop gecko-mediaplayer from buffering endlessly?

    - by mario
    I'm using the gecko-mediaplayer plugin (formerly "mplayerplug-in"). The totem plugin was not always working correctly with Opera, and I'm actually depending on the [Copy URL] feature of gecko-mediaplayer. However that plugin does some inept buffering of videos. It seems to default to 20% caching regardless of what you set in the preferences window. This is quite annoying for big video files. But appearantly it's by design http://groups.google.com/group/gecko-mediaplayer/browse_thread/thread/b7f0f5a3cedc8979 The Gentoo forums listed some workaround http://forums.gentoo.org/viewtopic-t-816690.html - but ~/.config/gecko-mediaplayer/gecko-mediaplayer.conf is not working in the Ubuntu version. Does anyone know the actual way to configure the cache= size. Which is the real configuration filename under Ubuntu?

    Read the article

  • Scan-Line Z-Buffering Dilemma

    - by Belgin
    I have a set of vertices in 3D space, and for each I retain the following information: Its 3D coordinates (x, y, z). A list of pointers to some of the other vertices with which it's connected by edges. Right now, I'm doing perspective projection with the projecting plane being XY and the eye placed somewhere at (0, 0, d), with d < 0. By doing Z-Buffering, I need to find the depth of the point of a polygon (they're all planar) which corresponds to a certain pixel on the screen so I can hide the surfaces that are not visible. My questions are the following: How do I determine to which polygon does a pixel belong to so I could use the formula of the plane which contains the polygon to find the Z-coordinate? Are my data structures correct? Do I need to store something else entirely in order for this to work? I'm just projecting the vertices onto the projection plane and joining them with lines based on the pointer lists.

    Read the article

  • Double Free inside of a destructor upon adding to a vector

    - by Shawn B
    Hey, I am working on a drum machine, and am having problems with vectors. Each Sequence has a list of samples, and the samples are ordered in a vector. However, when a sample is push_back on the vector, the sample's destructor is called, and results in a double free error. Here is the Sample creation code: class XSample { public: Uint8 Repeat; Uint8 PlayCount; Uint16 Beats; Uint16 *Beat; Uint16 BeatsPerMinute; XSample(Uint16 NewBeats,Uint16 NewBPM,Uint8 NewRepeat); ~XSample(); void GenerateSample(); void PlaySample(); }; XSample::XSample(Uint16 NewBeats,Uint16 NewBPM,Uint8 NewRepeat) { Beats = NewBeats; BeatsPerMinute = NewBPM; Repeat = NewRepeat-1; PlayCount = 0; printf("XSample Construction\n"); Beat = new Uint16[Beats]; } XSample::~XSample() { printf("XSample Destruction\n"); delete [] Beat; } And the 'Dynamo' code that creates each sample in the vector: class XDynamo { public: std::vector<XSample> Samples; void CreateSample(Uint16 NewBeats,Uint16 NewBPM,Uint8 NewRepeat); }; void XDynamo::CreateSample(Uint16 NewBeats,Uint16 NewBPM,Uint8 NewRepeat) { Samples.push_back(XSample(NewBeats,NewBPM,NewRepeat)); } Here is main(): int main() { XDynamo Dynamo; Dynamo.CreateSample(4,120,2); Dynamo.CreateSample(8,240,1); return 0; } And this is what happens when the program is run: Starting program: /home/shawn/dynamo2/dynamo [Thread debugging using libthread_db enabled] XSample Construction XSample Destruction XSample Construction XSample Destruction *** glibc detected *** /home/shawn/dynamo2/dynamo: double free or corruption (fasttop): 0x0804d008 *** However, when the delete [] is removed from the destructor, the program runs perfectly. What is causing this? Any help is greatly appreciated.

    Read the article

  • ArrayIndexOutOfBoundsException double array size

    - by Andy
    I'm going to preface this question with this statement: I know that I can easily handle this problem by reading the amount of lines in a file and making an array that size. I am not allowed to do this. Anyway, here is my question. I need to double my array's size whenever my program encounters an ArrayIndexOutOfBoundsException and then copy all the previous read in information into the larger array. Here is my code public static void main(String[] args) throws IOException { Scanner inScan, fScan = null; int [] A = new int[5]; inScan = new Scanner(System.in); System.out.print("Please enter the file to read from: "); while(true) { try{ String fName = inScan.nextLine(); fScan = new Scanner(new File(fName)); break; } catch (FileNotFoundException ex) { System.out.println("Your file is invalid -- please re-enter"); } } String nextItem; int nextInt = 0; int i = 0; while (fScan.hasNextLine()) { try { nextItem = fScan.nextLine(); nextInt = Integer.parseInt(nextItem); A[i] = nextInt; i++; } catch (NumberFormatException e) { System.out.println("Found an invalid int -- ignored"); } catch (ArrayIndexOutOfBoundsException e) { //double the size of array A until //copy all previous read in information to the larger array } } System.out.println("Here are your " + i + " items:"); for (int j = 0; j < i; j++) { System.out.println(A[j] + " "); } } }

    Read the article

  • Hotkey for double-click highlight?

    - by Steven Wright
    I'm working in Eclipse and find myself always replacing multiple copies of the same word, but I always have to take my hands off the keyboard and screen to get the mouse, hover over the word, double click to select, and then copy or rewrite the word. Is there any way I can just move the cursor inside the word and hit some hotkey that would highlight it? Seems like this would be a big timesaver. Or if there's a way to create a hotkey that would be perfect too.

    Read the article

  • Convert Delphi Real48 to C# double

    - by mjmcloug
    Hey, I need to be able to convert from a Delphi Real48 to C# double. I've got the bytes I need to convert but am looking for an elegant solution. to the problem. Anybody out there had to do this before? I'm needing to do the conversion in C# Thanks in advance

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >