Search Results

Search found 4022 results on 161 pages for 'float dublin'.

Page 40/161 | < Previous Page | 36 37 38 39 40 41 42 43 44 45 46 47  | Next Page >

  • Is this implementation truely tail-recursive?

    - by CFP
    Hello everyone! I've come up with the following code to compute in a tail-recursive way the result of an expression such as 3 4 * 1 + cos 8 * (aka 8*cos(1+(3*4))) The code is in OCaml. I'm using a list refto emulate a stack. type token = Num of float | Fun of (float->float) | Op of (float->float->float);; let pop l = let top = (List.hd !l) in l := List.tl (!l); top;; let push x l = l := (x::!l);; let empty l = (l = []);; let pile = ref [];; let eval data = let stack = ref data in let rec _eval cont = match (pop stack) with | Num(n) -> cont n; | Fun(f) -> _eval (fun x -> cont (f x)); | Op(op) -> _eval (fun x -> cont (op x (_eval (fun y->y)))); in _eval (fun x->x) ;; eval [Fun(fun x -> x**2.); Op(fun x y -> x+.y); Num(1.); Num(3.)];; I've used continuations to ensure tail-recursion, but since my stack implements some sort of a tree, and therefore provides quite a bad interface to what should be handled as a disjoint union type, the call to my function to evaluate the left branch with an identity continuation somehow irks a little. Yet it's working perfectly, but I have the feeling than in calling the _eval (fun y->y) bit, there must be something wrong happening, since it doesn't seem that this call can replace the previous one in the stack structure... Am I misunderstanding something here? I mean, I understand that with only the first call to _eval there wouldn't be any problem optimizing the calls, but here it seems to me that evaluation the _eval (fun y->y) will require to be stacked up, and therefore will fill the stack, possibly leading to an overflow... Thanks!

    Read the article

  • Help with listView in Android

    - by jul
    Hi, I'm just starting with Android and can't find how to display a list in my activity. I get some restaurant data from a web service and I'd like to show the results in a list. The activity, the restaurant class and the layout main.xml are shown below. How can I display, for instance, the list of the restaurant names in the ListView 'list' of my layout? thank you Jul public class Atable extends ListActivity { RestaurantList restaurantList; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //Here I set restaurantList //Now how can I display, for example, the list of the names of the restaurants } main.xml <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/search" /> <EditText android:id="@+id/search" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1"/> </LinearLayout> <LinearLayout android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ListView android:id="@+id/android:list" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/android:empty" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/noresults"/> </LinearLayout> </LinearLayout> Restaurant list class package org.digitalfarm.atable; import java.util.List; public class RestaurantList { private List<Restaurant> restaurants; public List<Restaurant> getRestaurants() { return restaurants; } public void setRestaurants(List<Restaurant> restaurants) { this.restaurants = restaurants; } } Restaurant class package org.digitalfarm.atable; public class Restaurant { private String name; private float latitude; private float longitude; public String getName() { return name; } public void setName(String name) { this.name = name; } public float getLatitude() { return latitude; } public void setLatitude(float latitude) { this.latitude = latitude; } public float getLongitude() { return longitude; } public void setLongitude(float longitude) { this.longitude = longitude; } }

    Read the article

  • Getting Segmentation Fault in C++, but why?

    - by Carlos
    I am getting segmentation fault in this code but i cant figure out why. I know a segmentation fault happens when a pointer is NULL, or when it points to a random memory address. #include <iostream> #include <fstream> #include <cmath> using namespace std; //**************************** CLASS ******************************* class Database { struct data{ string city; float latitude, longitude; data *link; }*p; public: Database(); void display(); void add(string cityName, float lat, float lon); private: string cityName; float lat, lon; }; //************************** CLASS METHODS ************************** Database::Database() { p = NULL; } void Database::add(string cityName, float lat, float lon){ data *q, *t; if(p == NULL){ p = new data; p -> city = cityName; p -> latitude = lat; p -> longitude = lon; p -> link = NULL; } else{ q = p; while(q -> link != NULL){ q = q -> link; } t = new data; t -> city = cityName; t -> latitude = lat; t -> longitude = lon; q -> link = t; } } void Database::display() { data *q; cout<<endl; for( q = p ; q != NULL ; q = q->link ) cout << endl << q -> city; } //***************************** MAIN ******************************* //*** INITIALIZATION *** Database D; void loadDatabase(); //****** VARIABLES ***** //******* PROGRAM ****** int main() { loadDatabase(); D.display(); } void loadDatabase() { int i = 0; string cityName; float lat, lon; fstream city; city.open("city.txt", ios::in); fstream latitude; latitude.open("lat.txt", ios::in); fstream longitude; longitude.open("lon.txt", ios::in); while(!city.eof()){ //************************************ city >> cityName; //* * latitude >> lat; //Here is where i think is the problem longitude >> lon; //* * D.add(cityName, lat, lon); //************************************ } city.close(); latitude.close(); longitude.close(); } This is the error am actually getting in console

    Read the article

  • Getting max. screen resolution with Group By

    - by Quandary
    Question: I have a website where I gather browser statistics. I have an SQL table (T_Visits), with the following columns: uniqueidentifier Visit_UID, uniqueidentifier User_UID, datetime Visit_DateTime, float Screen_w, float Screen_h, float Resolution = Screen_w * Screen_h varchar resolutionstring = screen_w + ' x ' + screen_h Now I want to get the maximum/minimum resolution each user had: Select User_UID, max(resolution) from T_Visits GROUP BY User_UID How can I get the corresponding resolution string ? I mean I can get the max(screen_w) and max(screen_h), but there's no guarantee that the corresponding resolutionstring would be max(screen_w) +' x '+ max(screen_h)

    Read the article

  • How to printf a time_t variable as a floating point number?

    - by soneangel
    Hi guys, I'm using a time_t variable in C (openMP enviroment) to keep cpu execution time...I define a float value sum_tot_time to sum time for all cpu's...I mean sum_tot_time is the sum of cpu's time_t values. The problem is that printing the value sum_tot_time it appear as an integer or long, by the way without its decimal part! I tried in these ways: to printf sum_tot_time as a double being a double value to printf sum_tot_time as float being a float value to printf sum_tot_time as double being a time_t value to printf sum_tot_time as float being a time_t value Please help me!!

    Read the article

  • How to structure (normalize?) a database of physical parameters?

    - by Arrieta
    Hello: I have a collection of physical parameters associated with different items. For example: Item, p1, p2, p3 a, 1, 2, 3 b, 4, 5, 6 [...] where px stands for parameter x. I could go ahead and store the database exactly as presented; the schema would be CREATE TABLE t1 (item TEXT PRIMARY KEY, p1 FLOAT, p2 FLOAT, p3 FLOAT); I could retrieve the parameter p1 for all the items with the statement: SELECT p1 FROM t1; A second alternative is to have an schema like: CREATE TABLE t1 (id INT PRIMARY KEY, item TEXT, par TEXT, val FLOAT) This seems much simpler if you have many parameters (as I do). However, the parameter retrieval seems very awkward: SELECT val FROM t1 WHERE par == 'p1' What do you advice? Should go for the "pivoted" (first) version or the id, par, val (second) version? Many thanks.

    Read the article

  • Naudio - putting audio stream into values [-1,1]

    - by denonth
    Hi all I need to put my audio stream into values of [-1,1]. Can someone tell me a good approach. I was reading byte array and float array from stream but I don't know what to do next. Here is my code: float[] bytes=new float[stream.Length]; float biggest= 0; for (int i = 0; i < stream.Length; i++) { bytes[i] = (byte)stream.ReadByte(); if (bytes[i] > biggest) { biggest=bytes[i]; } } and I don't know how to put values into stream. Because byte is only positive values. And I need to have from [-1,1] for (int i = 0; i < bytes.Count(); i++) { bytes[i] = (byte)(bytes[i] * (1 / biggest)); }

    Read the article

  • Why aren't operator conversions implicitly called for templated functions? (C++)

    - by John Gordon
    I have the following code: template <class T> struct pointer { operator pointer<const T>() const; }; void f(pointer<const float>); template <typename U> void tf(pointer<const float>); void g() { pointer<float> ptr; f(ptr); tf(ptr); } When I compile the code with gcc 4.3.3 I get a message (aaa.cc:17: error: no matching function for call to ‘tf(pointer<float>&)’) indicating that the compiler called 'operator pointer<const T>' for the non-templated function f(), but didn't for the templated function tf(). Why and is there any workaround short of overloading tf() with a const and non-const version? Thanks in advance for any help.

    Read the article

  • How do I send floats in window messages.

    - by yngvedh
    Hi, What is the best way to send a float in a windows message using c++ casting operators? The reason I ask is that the approach which first occurred to me did not work. For the record I'm using the standard win32 function to send messages: PostWindowMessage(UINT nMsg, WPARAM wParam, LPARAM lParam) What does not work: Using static_cast<WPARAM>() does not work since WPARAM is typedef'ed to UINT_PTR and will do a numeric conversion from float to int, effectively truncating the value of the float. Using reinterpret_cast<WPARAM>() does not work since it is meant for use with pointers and fails with a compilation error. I can think of two workarounds at the moment: Using reinterpret_cast in conjunction with the address of operator: float f = 42.0f; ::PostWindowMessage(WM_SOME_MESSAGE, *reinterpret_cast<WPARAM*>(&f), 0); Using an union: union { WPARAM wParam, float f }; f = 42.0f; ::PostWindowMessage(WM_SOME_MESSAGE, wParam, 0); Which of these are preffered? Are there any other more elegant way of accomplishing this?

    Read the article

  • SharpGL: Can't draw all lines from List

    - by Miko Kronn
    I have: float[,] nodesN = null; //indexes: //number of node; //value index 0->x, 1->y, 2->temperature int[,] elements = null; //indexes: //indexof element (triangle) //1, 2, 3 - vertexes (from nodesN) List<Pair> edges = null; //Pair is a class containing two int values which are //indexes of nodesN And function which is supposed do all elements and edges on SharpGL.OpenGLCtrl private void openGLCtrl1_Load(object sender, EventArgs e) { gl = this.glCtrl.OpenGL; gl.ClearColor(this.BackColor.R / 255.0f, this.BackColor.G / 255.0f, this.BackColor.B / 255.0f, 1.0f); gl.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT); } float glMinX = -2f; float glMaxX = 2f; float glMinY = -2f; float glMaxY = 2f; private void openGLControl1_OpenGLDraw(object sender, PaintEventArgs e) { gl.Clear(OpenGL.COLOR_BUFFER_BIT | OpenGL.DEPTH_BUFFER_BIT); gl.LoadIdentity(); gl.Translate(0.0f, 0.0f, -6.0f); if (!draw) return; bool drawElements = false; if (drawElements) { gl.Begin(OpenGL.TRIANGLES); for (int i = 0; i < elementNo; i++) { for (int j = 0; j < 3; j++) { float x, y, t; x = nodesN[elements[i, j], 0]; y = nodesN[elements[i, j], 1]; t = nodesN[elements[i, j], 2]; gl.Color(t, 0.0f, 1.0f - t); gl.Vertex(x, y, 0.0f); } } gl.End(); } gl.Color(0f, 0f, 0f); gl.Begin(OpenGL.LINES); //for(int i=edges.Count-1; i>=0; i--) for(int i=0; i<edges.Count; i++) { float x1, y1, x2, y2; x1 = nodesN[edges[i].First, 0]; y1 = nodesN[edges[i].First, 1]; x2 = nodesN[edges[i].Second, 0]; y2 = nodesN[edges[i].Second, 1]; gl.Vertex(x1, y1, 0.0f); gl.Vertex(x2, y2, 0.0f); } gl.End(); } But it doesn't draw all the edges. If i change drawElements it draws different number of edges. Changing for(int i=0; i<edges.Count; i++) to for(int i=edges.Count-1; i>=0; i--) shows that esges are generated correctly, but they are not drawn. Images: for(int i=0; i<edges.Count; i++) drawElements=false for(int i=edges.Count-1; i>=0; i--) drawElements=false for(int i=0; i<edges.Count; i++) drawElements=true for(int i=edges.Count-1; i>=0; i--) drawElements=true What is wrong with this? How can I draw all edges?

    Read the article

  • Counting point size based on chart area during zooming/unzoomin

    - by Gacek
    Hi folks. I heave a quite simple task. I know (I suppose) it should be easy, but from the reasons I cannot understand, I try to solve it since 2 days and I don't know where I'm making the mistake. So, the problem is as follows: - we have a chart with some points - The chart starts with some known area and points have known size - we would like to "emulate" the zooming effect. So when we zoom to some part of the chart, the size of points is getting proportionally bigger. In other words, the smaller part of the chart we select, the bigger the point should get. So, we have something like that. We know this two parameters: initialArea; // Initial area - area of the whole chart, counted as width*height initialSize; // initial size of the points Now lets assume we are handling some kind of OnZoom event. We selected some part of the chart and would like to count the current size of the points float CountSizeOnZoom() { float currentArea = CountArea(...); // the area is counted for us. float currentSize = initialSize * initialArea / currentArea; return currentSize; } And it works. But the rate of change is too fast. In other words, the points are getting really big too soon. So I would like the currentSize to be invertly proportional to currentArea, but with some scaling coefficient. So I created the second function: float CountSizeOnZoom() { float currentArea = CountArea(...); % the area is counted for us. // Lets assume we want the size of points to change ten times slower, than area of the chart changed. float currentSize = initialSize + 0.1f* initialSize * ((initialArea / currentArea) -1); return currentSize; } Lets do some calculations in mind. if currentArea is smaller than initialArea, initialArea/currentArea > 1 and then we add "something" small and postive to initialSize. Checked, it works. Lets check what happens if we would un-zoom. currentArea will be equal to initialArea, so we would have 0 at the right side (1-1), so new size should be equal to initialSize. Right? Yeah. So lets check it... and it doesn't work. My question is: where is the mistake? Or maybe you have any ideas how to count this scaled size depending on current area in some other way?

    Read the article

  • SASS mixin for swapping images / floats on site language (change)

    - by DBUK
    Currently using SASS on a website build. It is my first project using it, tried a little LESS before and liked it. I made a few basic mixins and variables with LESS, super useful stuff! I am trying to get my head around SASS mixins, and syntax, specifically for swapping images when the page changes to a different language, be that with body ID changing or <html lang="en">. And, swapping floats around if, for example, a website changed to chinese. So a mixin where float left is float left unless language is AR and then it becomes float right. With LESS I think it would be something like: .headerBg() when (@lang = en) {background-image:url(../img/hello.png);} .headerBg() when (@lang = it) {background-image:url(../img/ciao.png);} .header {.headerBg(); width: 200px; height:100px} .floatleft() when (@lang = en) { float: left;} .floatleft() when (@lang = ar) { float: right;} .logo {.floatleft();} Its the syntax I am having problems with combined with a brain melting day.

    Read the article

  • C pointer array scope and function calls

    - by juvenis
    I have this situation: { float foo[10]; for (int i = 0; i < 10; i++) { foo[i] = 1.0f; } object.function1(foo); // stores the float pointer to a const void* member of object } object.function2(); // uses the stored void pointer Are the contents of the float pointer unknown in the second function call? It seems that I get weird results when I run my program. But if I declare the float foo[10] to be const and initialize it in the declaration, I get correct results. Why is this happening?

    Read the article

  • warning about data loss c++/c

    - by Dr Deo
    i am getting a benign warning about possible data loss warning C4244: 'argument' : conversion from 'const int' to 'float', possible loss of data question i remember as if float has a larger precision than int. So how can data be lost if i convert from a smaller data type (int) to a larger data type (float)

    Read the article

  • Nonstatic conversion functions; Casting different types, e.g. DirectX vector to OpenGL vector

    - by Markus
    I am currently working on a game "engine" that needs to move values between a 3D engine, a physics engine and a scripting language. Since I need to apply vectors from the physics engine to 3D objects very often and want to be able to control both the 3D, as well as the physics objects through the scripting system, I need a mechanism to convert a vector of one type (e.g. vector3d<float>) to a vector of the other type (e.g. btVector3). Unfortunately I can make no assumptions on how the classes/structs are laid out, so a simple reinterpret_cast probably won't do. So the question is: Is there some sort of 'static'/non-member casting method to achieve basically this: vector3d<float> operator vector3d<float>(btVector3 vector) { // convert and return } btVector3 operator btVector3(vector3d<float> vector) { // convert and return } Right now this won't compile since casting operators need to be member methods. (error C2801: 'operator foo' must be a non-static member)

    Read the article

  • Error while converting function from oracle to SQL Server

    - by sss
    Hi, I am migrating a function from Oracle to SQL Server 2008. This function raises SELECT statements included within a function cannot return data to a client as error. How can I solve this problem? Original PLSQL Code CREATE OR REPLACE function f_birim_cevrim_katsayi (p_ID_MAMUL in number, p_ID_BIRIMDEN in number, p_ID_BIRIME in number) return number is v_katsayi number; begin v_katsayi:=0; if p_ID_BIRIMDEN!=p_ID_BIRIME then for c in ( select * from CR_BIRIM_CEVRIM where ID_MAMUL = p_ID_MAMUL and ( (ID_BIRIM = p_ID_BIRIMDEN and ID_BIRIM2 = p_ID_BIRIME) OR ( ID_BIRIM2 = p_ID_BIRIMDEN and ID_BIRIM = p_ID_BIRIME) ) and VALID = 1) loop if c.ID_BIRIM=p_ID_BIRIMDEN then v_katsayi:=c.MT_ORAN; else v_katsayi:=1/c.MT_ORAN; end if; end loop; else v_katsayi:=1; end if; return round(v_katsayi,10); exception when others then return 0; end; T-SQL code: If Exists ( SELECT name FROM sysobjects WHERE name = 'f_birim_cevrim_katsayi' AND type = 'FN') DROP FUNCTION f_birim_cevrim_katsayi GO CREATE FUNCTION f_birim_cevrim_katsayi ( @p_ID_MAMUL FLOAT , @p_ID_BIRIMDEN FLOAT , @p_ID_BIRIME FLOAT ) RETURNS float AS BEGIN DECLARE @adv_error INT DECLARE @v_katsayi FLOAT SELECT @v_katsayi = 0 IF @p_ID_BIRIMDEN != @p_ID_BIRIME BEGIN DECLARE cursor_for_inline_select1 CURSOR LOCAL FOR SELECT * FROM CR_BIRIM_CEVRIM WHERE ID_MAMUL = @p_ID_MAMUL AND ((ID_BIRIM = @p_ID_BIRIMDEN AND ID_BIRIM2 = @p_ID_BIRIME) OR (ID_BIRIM2 = @p_ID_BIRIMDEN AND ID_BIRIM = @p_ID_BIRIME)) AND VALID = 1 OPEN cursor_for_inline_select1 FETCH NEXT FROM cursor_for_inline_select1 WHILE (@@FETCH_STATUS <> -1) BEGIN IF c.ID_BIRIM = @p_ID_BIRIMDEN BEGIN SELECT @v_katsayi = c.MT_ORAN END ELSE BEGIN SELECT @v_katsayi = 1/c.MT_ORAN END END CLOSE cursor_for_inline_select1 DEALLOCATE cursor_for_inline_select1 END ELSE BEGIN SELECT @v_katsayi = 1 END DEALLOCATE cursor_for_inline_select1 return ROUND(@v_katsayi, 10) GOTO ExitLabel1 Exception1: BEGIN DEALLOCATE cursor_for_inline_select1 return 0 END ExitLabel1: return ROUND(@v_katsayi, 10) END GO

    Read the article

  • Help with code optimization

    - by Ockonal
    Hello, I've written a little particle system for my 2d-application. Here is raining code: // HPP ----------------------------------- struct Data { float x, y, x_speed, y_speed; int timeout; Data(); }; std::vector<Data> mData; bool mFirstTime; void processDrops(float windPower, int i); // CPP ----------------------------------- Data::Data() : x(rand()%ScreenResolutionX), y(0) , x_speed(0), y_speed(0), timeout(rand()%130) { } void Rain::processDrops(float windPower, int i) { int posX = rand() % mWindowWidth; mData[i].x = posX; mData[i].x_speed = WindPower*0.1; // WindPower is float mData[i].y_speed = Gravity*0.1; // Gravity is 9.8 * 19.2 // If that is first time, process drops randomly with window height if (mFirstTime) { mData[i].timeout = 0; mData[i].y = rand() % mWindowHeight; } else { mData[i].timeout = rand() % 130; mData[i].y = 0; } } void update(float windPower, float elapsed) { // If this is first time - create array with new Data structure objects if (mFirstTime) { for (int i=0; i < mMaxObjects; ++i) { mData.push_back(Data()); processDrops(windPower, i); } mFirstTime = false; } for (int i=0; i < mMaxObjects; i++) { // Sleep until uptime > 0 (To make drops fall with randomly timeout) if (mData[i].timeout > 0) { mData[i].timeout--; } else { // Find new x/y positions mData[i].x += mData[i].x_speed * elapsed; mData[i].y += mData[i].y_speed * elapsed; // Find new speeds mData[i].x_speed += windPower * elapsed; mData[i].y_speed += Gravity * elapsed; // Drawing here ... // If drop has been falled out of the screen if (mData[i].y > mWindowHeight) processDrops(windPower, i); } } } So the main idea is: I have some structure which consist of drop position, speed. I have a function for processing drops at some index in the vector-array. Now if that's first time of running I'm making array with max size and process it in cycle. But this code works slower that all another I have. Please, help me to optimize it. I tried to replace all int with uint16_t but I think it doesn't matter.

    Read the article

  • Function Returning Negative Value

    - by Geowil
    I still have not run it through enough tests however for some reason, using certain non-negative values, this function will sometimes pass back a negative value. I have done a lot of manual testing in calculator with different values but I have yet to have it display this same behavior. I was wondering if someone would take a look at see if I am missing something. float calcPop(int popRand1, int popRand2, int popRand3, float pERand, float pSRand) { return ((((((23000 * popRand1) * popRand2) * pERand) * pSRand) * popRand3) / 8); } The variables are all contain randomly generated values: popRand1: between 1 and 30 popRand2: between 10 and 30 popRand3: between 50 and 100 pSRand: between 1 and 1000 pERand: between 1.0f and 5500.0f which is then multiplied by 0.001f before being passed to the function above Edit: Alright so after following the execution a bit more closely it is not the fault of this function directly. It produces an infinitely positive float which then flips negative when I use this code later on: pPMax = (int)pPStore; pPStore is a float that holds popCalc's return. So the question now is, how do I stop the formula from doing this? Testing even with very high values in Calculator has never displayed this behavior. Is there something in how the compiler processes the order of operations that is causing this or are my values simply just going too high? If the later I could just increase the division to 16 I think.

    Read the article

  • how to avoid clutch billiard balls?

    - by Nait87
    I'm working on the simple behaviour of billiard balls in a collision with each other. All works normal, but there was a problem when facing a few easy balls is the effect of coupling balls and they're cool with each other. Tell me how to prevent this. bool MGBilliard::CollisingBall(CCPoint curr_point, CCPoint next_point) { float dx = next_point.x - (curr_point.x + dvdt.x); float dy = next_point.y - (curr_point.y - dvdt.y); float d = dx*dx+dy*dy; return d <= BALL_RADIUS * BALL_RADIUS; } double MGBilliard::angleCollisionBalls(Ball* current, Ball* next) { double na; double dx = fabs(next->location.x - current->location.x); double dy = fabs(next->location.y - current->location.y); na = atan(fabs(dy/dx)); if(atan(fabs(current->location.y/current->location.x)) < atan(fabs(next->location.y/next->location.x))) na = current->angle - na; else if(atan(fabs(current->location.y/current->location.x)) > atan(fabs(next->location.y/next->location.x))) na = current->angle + na; return na; } for(unsigned int i = 0;i<BALL_COUNT;++i) { if(vBalls[i]->speed > 0){ vBalls[i]->speed += vBalls[i]->acceleration; float dsdt = vBalls[i]->speed*dt; dvdt.x = dsdt*cos(vBalls[i]->angle); dvdt.y = dsdt*sin(vBalls[i]->angle); vBalls[i]->location.x += dvdt.x; vBalls[i]->location.y += dvdt.y; for(unsigned int j = 1; j < BALL_COUNT; ++j) { if(i == j) continue; if(CollisingBall(vBalls[i]->spriteBall->getPosition(),vBalls[j]->spriteBall->getPosition())) { vBalls[j]->speed = 600; double angle; angle = angleCollisionBalls(vBalls[i],vBalls[j]); vBalls[i]->angle = (float)-angle; vBalls[j]->angle = (float)angle; } } } }

    Read the article

  • How to get the number of loop when using an iterator, in C++?

    - by pollux
    Dear reader, I'm working on a aplication where I draw a couple of images, like this: void TimeSlice::draw(float fX, float fY) { list<TimeSliceLevel*>::iterator it = levels.begin(); float level_x = x; float level_y = y; while(it != levels.end()) { (*it)->draw(level_x,level_y); level_y += (*it)->height; ++it; } } Though this is a bit incorrect. I need to position the TimeSliceLevel* on a X.. When I've got a for(int i = 0; i < slices.size(); ++i) loop, I can use x = i * width. Though I'm using an iterator as I've been told many times that's good programming : and I'm wondering if the iterator has a "index" number of something which I can use to calculate the new X position? (So it's more a question about using iterators) Kind regards, Pollux

    Read the article

  • Function Overloading

    - by Sanju
    Let us suppose i have these three methods defined: int F1(int, int); int F1(float, float); Float F1(int, int); and i am calling method F1 here: Console.writeline(F1(5,6).ToString())); Which method it will call and why?

    Read the article

  • struct constructor + function parameter

    - by Oops
    Hi, I am a C++ beginner. I have the following code, the reult is not what I expect. The question is why, resp. what is wrong. For sure, the most of you see it at the first glance. struct Complex { float imag; float real; Complex( float i, float r) { imag = i; real = r; } Complex( float r) { Complex(0, r); } std::string str() { std::ostringstream s; s << "imag: " << imag << " | real: " << real << std::endl; return s.str(); } }; class Complexes { std::vector<Complex> * _complexes; public: Complexes(){ _complexes = new std::vector<Complex>; } void Add( Complex elem ) { _complexes->push_back( elem ); } std::string str( int index ) { std::ostringstream oss; Complex c = _complexes->at(index); oss << c.str(); return oss.str(); } }; int main(){ Complexes * cs = new Complexes(); //cs->Add(123.4f); cs->Add(Complex(123.4f)); std::cout << cs->str(0); return 0; } for now I am interested in the basics of c++ not in the complexnumber theory ;-) it would be nice if the "Add" function does also accept one real (without an extra overloading) instead of only a Complex-object is this possible? many thanks in advance Oops

    Read the article

  • Problem with calculating floats

    - by iFloh
    strange situation, when performing the following lines of Code: const float a = 47.848711; const float b = 47.862952; float result = b - a; I get a (NSLog %.10f) result = 0.0142440796. I expected to get 0.0142410000. What's going on?

    Read the article

< Previous Page | 36 37 38 39 40 41 42 43 44 45 46 47  | Next Page >