Search Results

Search found 6094 results on 244 pages for 'double gras'.

Page 67/244 | < Previous Page | 63 64 65 66 67 68 69 70 71 72 73 74  | Next Page >

  • boost::spirit::karma using the alternatives operator (|) with conditions

    - by Ingemar
    I'm trying to generate a string from my own class called Value using boost::spirit::karma, but i got stuck with this. I've tried to extract my problem into a simple example. I want to generate a String with karma from instances of the following class: class Value { public: enum ValueType { BoolType, NumericType }; Value(bool b) : type_(BoolType), value_(b) {} Value(const double d) : type_(NumericType), value_(d) {}; ValueType type() { return type_; } operator bool() { return boost::get<bool>(value_); } operator double() { return boost::get<double>(value_); } private: ValueType type_; boost::variant<bool, double> value_; }; Here you can see what I'm tying to do: int main() { using karma::bool_; using karma::double_; using karma::rule; using karma::eps; std::string generated; std::back_insert_iterator<std::string> sink(generated); rule<std::back_insert_iterator<std::string>, Value()> value_rule = bool_ | double_; Value bool_value = Value(true); Value double_value = Value(5.0); karma::generate(sink, value_rule, bool_value); std::cout << generated << "\n"; generated.clear(); karma::generate(sink, value_rule, double_value); std::cout << generated << "\n"; return 0; } The first call to karma::generate() works fine because the value is a bool and the first generator in my rule also "consumes" a bool. But the second karma::generate() fails with boost::bad_get because karma tries to eat a bool and calls therefore Value::operator bool(). My next thought was to modify my generator rule and use the eps() generator together with a condition but here i got stuck: value_rule = (eps( ... ) << bool_) | (eps( ... ) << double_); I'm unable to fill the brackets of the eps generator with sth. like this (of course not working): eps(value.type() == BoolType) I've tried to get into boost::phoenix, but my brain seems not to be ready for things like this. Please help me! here is my full example (compiling but not working): main.cpp

    Read the article

  • C# coding standards for private member variables [closed]

    - by Sasha
    I saw two common approaches for coding standards for private member variables: class Foo { private int _i; private string _id; } and class Foo { private int m_i; private string m_id; } I believe the latter is coming from C++. Also, many people specify type before the member variable: double m_dVal -- to indicate that is is a nonconstant member variable of the type double? What are the conventions in C#?

    Read the article

  • Calling a Add-in function from Excel's VBA

    - by graham
    I am using an Excel Add-in for an Erlangs: http://abstractmicro.com/erlang/helppages/ref-erlbblockage.htm I try to call the Erlang-B function within the Add-in from within VBA thus: Function Erl(Erlangs As Double, Capacity As Double) Erl = Application.WorksheetFunction.ErlbBlockage(Capacity, Erlangs) End Function ...but it doesn't work. I get #VALUE! returned in the Excel cell. I think it is because the function is not part of standard Excel (it is in the Add-in). So how do I call it?

    Read the article

  • Format the output of a string

    - by prince23
    hi here string strScore="2"; or string strScore="2.45656" now here i am checking the condition if it is double value = double.Parse(strScore); strScore = value.ToString("##.##"); 2.45656 like this then i am showing the output as 2.45 if the input is string strScore="2"; then the ouput is shown as "2" but now i need to show the output has 2.00 how can i format the code like this based on the condition

    Read the article

  • Worst Case number of rotations for BST to AVL algorithm?

    - by spacker_lechuck
    I have a basic algorithm below and I know that the worst case input BST is one that has degenerated to a linked list from inserts to only one side. How would I compute the worst case complexity in terms of number of rotations for this BST to AVL conversion algorithm? IF tree is right heavy { IF tree's right subtree is left heavy { Perform Double Left rotation } ELSE { Perform Single Left rotation } } ELSE IF tree is left heavy { IF tree's left subtree is right heavy { Perform Double Right rotation } ELSE { Perform Single Right rotation } }

    Read the article

  • Building a DataTable in C# with one column at a time

    - by Awaken
    I am trying to build a Retirement Calculator as a chance to make something useful and learn C# better. Currently, I am trying to build a DataTable with a dynamic amount of rows/columns. For context, I ask the user for some inputs regarding salary, % of salary being invested, and expected ROI. I have some other stuff too, but it isn't really part of the issue I am having. Because the number of columns I need for the DataTable is unknown until the formula is run (while+for loop completes), I am having trouble doing things as DataColumns. Hopefully the code below will help. I am really trying to build the table one column at a time. I realize I could reverse it to build it one row at a time because the Years before retirement (yearsRetire) is known, but I would prefer not to and I want to learn more. Sorry for the indentation and commenting. I tried to leave some of my commented coding attempts in there. Thanks for any help. public double calcROI() { double testROI = 0.00; double tempRetireAmount = 0; double adjustRetire = goalAmount * (1 + (Math.Pow(inflation,yearsRetire))); // Loop through ROI values until the calculated retire amount with the test ROI // is greater than the target amount adjusted for inflation while (tempRetireAmount < adjustRetire) { //Increment ROI by 1% per while iteration testROI += .01; //Make a new Column to hold the values for ROI for this while iteration //dtMain.Columns.Add(Convert.ToString(testROI)); //DataColumn tempdc = new DataColumn(Convert.ToString(testROI)); //Loop through the number of years entered by user and see the amount //at Retirement with current ROI for (int i = 0; i < yearsRetire; i++) { //Main formula to calculate amount after i years tempRetireAmount = (tempRetireAmount + salary*savingsPct) * (1 + testROI); // Add value for this year/ROI to table/column //DataRow dr = .NewRow(); //dr tempRetireAmount; //tempdc[i] = tempRetireAmount; } //Need to add column of data to my Main DataTable //dtMain.Rows.Add(dr); //dtMain.Columns.Add(tempdc); } return testROI; }

    Read the article

  • C# rendering graph

    - by subodh
    i have to render a graph in my web page.i have desigened a class( in C#) file which contain a event for rendering a graph(pie chart).In that event i pass some value i.e legends which is a string[] and value which is double[] to draw the graph. But i want that instead of inserting the value directly into the event, pass that value with some function like public void insertvalue(string[] legends,double[] values) { } how could i do that plese help me???????? And i am using Zedgraphweb control to render the graph.

    Read the article

  • ms-access: displaying column as "something else"

    - by every_answer_gets_a_point
    i have the following access sql statement: SELECT * FROM (SELECT [Occurrence Number], [Occurrence Date], [1 0 Preanalytical (Before Testing)], [Cup Type], NULL as '2 0 Analytical (Testing Phase)', [2 0 Area], NULL,NULL FROM [Lab Occurrence Form] WHERE NOT ([1 0 Preanalytical (Before Testing)] IS NULL) in this: NULL as '2 0 Analytical (Testing Phase)' when it displays the column it shows the single quote. if i remove the quote completely it gives me an error, if i use double quotes it shows me the double quotes in the resulting table is it possible to not have it show any quotes?

    Read the article

  • Another Spring + Hibernate + JPA question

    - by Albinoswordfish
    I'm still struggling with changing my Spring Application to use Hibernate with JPA to do database activities. Well apparently from a previous post I need an persistence.xml file. However do I need to make changes to my current DAO class? public class JdbcProductDao extends Dao implements ProductDao { /** Logger for this class and subclasses */ protected final Log logger = LogFactory.getLog(getClass()); public List<Product> getProductList() { logger.info("Getting products!"); List<Product> products = getSimpleJdbcTemplate().query( "select id, description, price from products", new ProductMapper()); return products; } public void saveProduct(Product prod) { logger.info("Saving product: " + prod.getDescription()); int count = getSimpleJdbcTemplate().update( "update products set description = :description, price = :price where id = :id", new MapSqlParameterSource().addValue("description", prod.getDescription()) .addValue("price", prod.getPrice()) .addValue("id", prod.getId())); logger.info("Rows affected: " + count); } private static class ProductMapper implements ParameterizedRowMapper<Product> { public Product mapRow(ResultSet rs, int rowNum) throws SQLException { Product prod = new Product(); prod.setId(rs.getInt("id")); prod.setDescription(rs.getString("description")); prod.setPrice(new Double(rs.getDouble("price"))); return prod; } } } Also my Product.Java is below public class Product implements Serializable { private int id; private String description; private Double price; public void setId(int i) { id = i; } public int getId() { return id; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Double getPrice() { return price; } public void setPrice(Double price) { this.price = price; } public String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("Description: " + description + ";"); buffer.append("Price: " + price); return buffer.toString(); } } I guess my question would be, How would my current classes change after using Hibernate + JPA with an Entity Manager

    Read the article

  • Copy operation fails when running executable using shortcut.

    - by MiloDC
    I've coded a C# executable that uses xcopy (cmd.exe /Q /D /C xcopy [args]) to duplicate some files. If I run the .exe by double-clicking it, the xcopy operation works every time. If I run the .exe by double-clicking a shortcut to the .exe, the xcopy works only if the shortcut is in the same folder as the .exe. This makes absolutely no sense to me, I wouldn't even know where to begin to find the answer. So, you know, help.

    Read the article

  • C++ choose function by return type.

    - by anon
    I realize standard C++ only picks functions by argument type, not return type. I.e I can do something like: void func(int); void func(double); but not double func(); int func(); Where in the former, it's clear, in the latter, it's ambigious. Are there any extensions that lets me tell C++ to pick which function to use also by return type? Thanks!

    Read the article

  • Collision Detection probelm (intersection with plane)

    - by Demi
    I'm doing a scene using openGL (a house). I want to do some collision detection, mainly with the walls in the house. I have tried the following code: // a plane is represented with a normal and a position in space Vector planeNor(0,0,1); Vector position(0,0,-10); Plane p(planeNor,position); Vector vel(0,0,-1); double lamda; // this is the intersection point Vector pNormal; // the normal of the intersection // this method is from Nehe's Lesson 30 coll= p.TestIntersionPlane(vel,Z,lamda,pNormal); glPushMatrix(); glBegin(GL_QUADS); if(coll) glColor3f(1,0,0); else glColor3f(1,1,1); glVertex3d(0,0,-10); glVertex3d(3,0,-10); glVertex3d(3,3,-10); glVertex3d(0,3,-10); glEnd(); glPopMatrix(); Nehe's method: #define EPSILON 1.0e-8 #define ZERO EPSILON bool Plane::TestIntersionPlane(const Vector3 & position,const Vector3 & direction, double& lamda, Vector3 & pNormal) { double DotProduct=direction.scalarProduct(normal); // Dot Product Between Plane Normal And Ray Direction double l2; // Determine If Ray Parallel To Plane if ((DotProduct<ZERO)&&(DotProduct>-ZERO)) return false; l2=(normal.scalarProduct(position))/DotProduct; // Find Distance To Collision Point if (l2<-ZERO) // Test If Collision Behind Start return false; pNormal= normal; lamda=l2; return true; } Z is initially (0,0,0) and every time I move the camera towards the plane, I reduce its z component by 0.1 (i.e. Z.z-=0.1 ). I know that the problem is with the vel vector, but I can't figure out what the right value should be. Can anyone please help me?

    Read the article

  • Mutable objects and hashCode

    - by robert
    Have the following class: public class Member { private int x; private long y; private double d; public Member(int x, long y, double d) { this.x = x; this.y = y; this.d = d; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + x; result = (int) (prime * result + y); result = (int) (prime * result + Double.doubleToLongBits(d)); return result; } @Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof Member) { Member other = (Member) obj; return other.x == x && other.y == y && Double.compare(d, other.d) == 0; } return false; } public static void main(String[] args) { Set<Member> test = new HashSet<Member>(); Member b = new Member(1, 2, 3); test.add(b); System.out.println(b.hashCode()); b.x = 0; System.out.println(b.hashCode()); Member first = test.iterator().next(); System.out.println(test.contains(first)); System.out.println(b.equals(first)); System.out.println(test.add(first)); } } It produces the following results: 30814 29853 false true true Because the hashCode depends of the state of the object it can no longer by retrieved properly, so the check for containment fails. The HashSet in no longer working properly. A solution would be to make Member immutable, but is that the only solution? Should all classes added to HashSets be immutable? Is there any other way to handle the situation? Regards.

    Read the article

  • C# drawing and invalidating 2 lines to meet

    - by BlueMonster
    If i have 2 lines on a page as such: e.Graphics.DrawLine(blackPen, w, h, h, w); e.Graphics.DrawLine(blackPen, w2, h2, h2, w2); how would i animate the first line to reach the second line's position? I have the following method which calculates the distance between two points (i'm assuming i would use this?) public int Distance2D(int x1, int y1, int x2, int y2) { // ______________________ //d = &#8730; (x2-x1)^2 + (y2-y1)^2 // //Our end result int result = 0; //Take x2-x1, then square it double part1 = Math.Pow((x2 - x1), 2); //Take y2-y1, then sqaure it double part2 = Math.Pow((y2 - y1), 2); //Add both of the parts together double underRadical = part1 + part2; //Get the square root of the parts result = (int)Math.Sqrt(underRadical); //Return our result return result; } How would i re-draw the line (on a timer) to reach the second line's position? I've looked a lot into XAML (story-boarding) and such - but i want to know how to do this on my own. Any ideas? I know i would need a method which runs in a loop re-drawing the line after moving the position a tid bit. I would have to call Invalidate() in order to make the line appear as though it's moving... but how would i do this? how would i move that line slowly over to the other line? I'm pretty sure i'd have to use double buffering if i'm doing this as well... as such: SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true); This doesn't quiet work, i'm not quiet sure how to fix it. Any ideas? protected override void OnPaint(PaintEventArgs e) { Distance2D(w, h, w2, h2); if (w2 != w && h2 != h) { e.Graphics.DrawLine(blackPen, (w * (int)frame), (h * (int)frame), (h * (int)frame), (w * (int)frame)); e.Graphics.DrawLine(blackPen, w2, h2, h2, w2); } else { t.Abort(); } base.OnPaint(e); } public void MoveLine() { for (int i = 0; i < 126; i++) { frame += .02; Invalidate(); Thread.Sleep(30); } } private void button1_Click(object sender, EventArgs e) { t = new Thread(new ThreadStart(MoveLine)); t.Start(); }

    Read the article

  • Should we use temporary variables for the returned values of functions?

    - by totymedli
    I thought about this: Is there a performance difference in these two practices: Store the return value of a function in a temporary variable than give that variable as a parameter to another function. Put the function into the other function. Specification Assuming all classes and functions are written correctly. Case 1. ClassA a = function1(); ClassB b = function2(a); function3(b); Case 2. function3(function2(function1())); I know there aren't a big difference with only one run, but supposed that we could run this a lot of times in a loop, I created some tests. Test #include <iostream> #include <ctime> #include <math.h> using namespace std; int main() { clock_t start = clock(); clock_t ends = clock(); // Case 1. start = clock(); for (int i=0; i<10000000; i++) { double a = cos(1); double b = pow(a, 2); sqrt(b); } ends = clock(); cout << (double) (ends - start) / CLOCKS_PER_SEC << endl; // Case 2. start = clock(); for (int i=0; i<10000000; i++) sqrt(pow(cos(1),2)); ends = clock(); cout << (double) (ends - start) / CLOCKS_PER_SEC << endl; return 0; } Results Case 1 = 6.375 Case 2 = 0.031 Why is the first one is much slower, and if the second one is faster why dont we always write code that way? Anyway does the second pratice has a name? I also wondered what happens if I create the variables outside the for loop in the first case, but the result was the same. Why?

    Read the article

  • Getting An Array Result From A C# Method

    - by Soo
    I am trying to write some code to return an array in C#, but don't know the proper syntax. I think my method is set up correctly, but to set an array to the result of the method is what I'm having difficulty with. Method Declaration: double[,] function(double variable) { ... code ... return array }

    Read the article

  • Flexible array member in C-structure

    - by Arpan
    Quoting from the C-std section 6.7.2.1, struct s { int n; double d[]; }; This is a valid structure declaration. I am looking for some practical use of this kind of syntax. To be precise, how is this construct any more or less powerful than keeping a double* as the 2nd element? Or is this another case of 'you-can-do-it-in-multiple-ways'? Arpan

    Read the article

  • How to get Ponter/Reference semantics in Scala.

    - by Lukasz Lew
    In C++ I would just take a pointer (or reference) to arr[idx]. In Scala I find myself creating this class to emulate a pointer semantic. class SetTo (val arr : Array[Double], val idx : Int) { def apply (d : Double) { arr(idx) = d } } Isn't there a simpler way? Doesn't Array class have a method to return some kind of reference to a particular field?

    Read the article

  • Speeding up Math calculations in Java

    - by Simon
    I have a neural network written in Java which uses a sigmoid transfer function defined as follows: private static double sigmoid(double x) { return 1 / (1 + Math.exp(-x)); } and this is called many times during training and computation using the network. Is there any way of speeding this up? It's not that it's slow, it's just that it is used a lot, so a small optimisation here would be a big overall gain.

    Read the article

< Previous Page | 63 64 65 66 67 68 69 70 71 72 73 74  | Next Page >