Search Results

Search found 1803 results on 73 pages for 'pi calculation'.

Page 50/73 | < Previous Page | 46 47 48 49 50 51 52 53 54 55 56 57  | Next Page >

  • Why is Java not telling me when I can't use Integer?

    - by Sebi
    For a small project (Problem 10 Project Euler) i tried to sum up all prime numbers below 2 millions. So I used a brute force method and iterated from 0 to 2'000'000 and checked if the number is a prime. If it is I added it to the sum: private int sum = 0; private void calculate() { for (int i = 0; i < 2000000; i++) { if (i.isPrime()) { sum = sum + i; } } sysout(sum) } The result of this calculation is 1179908154, but this is incorrect. So i changed int to BigInteger and now i get the correct sum 142913828922. Obviously the range of int was overflowed. But why can't Java tell my that? (e.g. by an exception)

    Read the article

  • Calling a method from within a django model save() override

    - by Jonathan
    I'm overriding a django model save() method. Within the override I'm calling another method of the same class and instance which calculates one of the instance's fields based on other fields of the same instance. class MyClass(models.Model): field1 = models.FloatField() field2 = models.FloatField() field3 = models.FloatField() def calculateField1(self) self.field1 = self.field2 + self.field3 def save(self, *args, **kwargs): self.calculateField1() super(MyClass, self).save(*args, **kwargs) The override method is called when I change the model in admin. Alas I've discovered that within calculateField1() field2 and field3 have the values of the instance from before I edited them in admin. If I enter the instance again in admin and save again, only then field1 receives the correct value as field2 and field3 are already updated. Is this the correct behavior on django's side? If yes, then how can I use the new values within calculateField1? I cannot implement the calculation within the save() as calculateField1() actually quite long and I need it to be called from elsewhere.

    Read the article

  • How to avoid the same calculations on column values over and over again in a select?

    - by Peter
    I sometimes write SELECTs on the form: SELECT a.col1+b.col2*c.col4 as calc_col1, a.col1+b.col2*c.col4 + xxx as calc_col1_PLUS_MORE FROM .... INNER JOIN ... ON a.col1+b.col2*c.col4 < d.some_threshold WHERE a.col1+b.col2*c.col4 > 0 When the calculations get rather involved and used up to 3-5 times within the same SELECT, I would really like to refactor that out in a function or similar in order to 1) hopefully improve performance / make use of cache 2) avoid forgetting to update one of the 4 calculations when I at a later stage realize I need to change the calculation. I usually have these selects within SPs. Any ideas?

    Read the article

  • Most efficient way to check if a date falls between two dates?

    - by Dave Jarvis
    Given: Start Month & Start Day End Month & End Day Any Year What SQL statement results in TRUE if a date lands between the Start and End days? 1st example: Start Date = 11-22 End Date = 01-17 Year = 2009 Specific Date = 2010-01-14 TRUE 2nd example: Start Date = 11-22 End Date = 11-16 Year = 2009 Specific Date = 2010-11-20 FALSE 3rd example: Start Date = 02-25 End Date = 03-19 Year = 2004 Specific Date = 2004-02-29 TRUE I was thinking of using the MySQL functions datediff and sign plus a CASE condition to determine whether the year wraps, but it seems rather expensive. Am looking for a simple, efficient calculation. Update The problem is the end date cannot simply use the year. The year must be increased if the end month/day combination happens before the start date. The start date is easy: Start Date = date( concat_ws( '-', year, Start Month, Start Day ) The end date is not so simple. Thank you!

    Read the article

  • Adjust SQL query to DB2

    - by Guy Roth
    Part of a complex query that our app is running contains the lines: ...(inner query) SELECT ... NULL as column_A, NULL as column_B, ... FROM ... This syntax of creating columns with null values is not allowed in DB2 altough it is totally OK in MSSQL and Oracle DBs. Technically I can change it to: '' as column_A, '' as column_B, But this doesn't have exactly the same meaning and can damage our calculation results. How can I create columns with null values in DB2 using other syntax??

    Read the article

  • AS3: How to access pixel data efficiently?

    - by JonoRR
    I'm working a game. The game requires entities to analyse an image and head towards pixels with specific properties (high red channel, etc.) I've looked into Pixel Bender, but this only seems useful for writing new colors to the image. At the moment, even at a low resolution (200x200) just one entity scanning the image slows to 1-2 Frames/second. I'm embedding the image and instance it as a Bitmap as a child of the stage. The 1-2 FPS situation is using BitmapData.getPixel() (on each pixel) with a distance calculation beforehand. I'm wondering if there's any way I can do this more efficiently... My first thought was some sort of spatial partioning coupled with splitting the image up into many smaller pieces. I also feel like Pixel Bender should be able to help somehow, however I've had little experience with it. Cheers for any help. Jonathan

    Read the article

  • Things to do with supercomputer.

    - by BigBoss
    HI, Guys I wanted to create SuperComputer out of my 3 old pcs soon. There are bunch of techniquies available on net for doing this and I will be using one of them. What I would like to get suggestion is what is next !! Many of them suggest some mathematical calculation or some graphic image rendering, which still is to me so boring and not inspiring at all. Please try to suggest something out of box. I would post results of it when I am done. Cheers !

    Read the article

  • Any way to do slanted/diagonal mouseovers via css/javascript?

    - by cksubs
    Hi, I have a box built via html borders. I want to connect the bottom left corner to the top right corner with a diagonal line. Either with html/css or by using a background image, doesn't matter. I'll figure that part out later. ------ - /- - / - - / - -/---- Here's the tricky part: I want a different thing to happen depending on which side of the line the mouse is hovering over. I'll do something like make some text visible or change the background color. Is that possible in web programing? I've thought of doing a "Riemann sum" type calculation with a bunch of invisible divs. Any easier way? Thanks!

    Read the article

  • Gradient a Parallelogram

    - by nuclearpenguin
    I'm working in JavaScript drawing on a canvas, and have four coordinates to draw a parallelogram, called A, B, C, and D starting from the top-left, top-right, bottom-left, and bottom right, respectively. An example of some coordinates might be: A: (3, 3) B: (4, 3) C: (1, 0) D: (2, 0) I can draw the parallelogram just fine, but I would like to fill it in with a gradient. I want the gradient to fill in from left to right, but matching the angle of the shape. The library I use (CAKE) requires a start and stop coordinate for the gradient. My stop and start would be somewhere half way between A and C, and end somewhere half way between B and D. Of course, it is not simply EXACTLY half way because the angles at A, B, C, and D are not right angles. So given this information (the coordinates), how to I find the point on the line A - C to start, and the point on the line B - D to stop? Remember, I'm doing this in JavaScript, so I have some good Math tools at my disposal for calculation.

    Read the article

  • Phantom updates due to decimal precision on calculated properties

    - by Jamie Ide
    This article describes my problem. I have several properties that are calculated. These are typed as decimal(9,2) in SQL Server and decimal in my C# classes. An example of the problem is: Object is loaded with a property value of 14.9 A calculation is performed and the property value is changed to 14.90393 When the session is flushed, NHibernate issues an update because the property is dirty Since the database field is decimal (9,2) the stored value doesn't change Basically a phantom update is issued every time this object is loaded. I don't want to truncate the calculations in my business objects because that tightly couples them to the database and I don't want to lose the precision in other calculations. I tried setting scale and precision or CustomType("Decimal(9,2)") in the mapping file but this appears to only affect schema generation. My only reasonable option appears to be creating an IUserType implementation to handle this. Is there a better solution?

    Read the article

  • How to optimize Dijkstra algorithm for a single shortest path between 2 nodes?

    - by Nazgulled
    Hi, I was trying to understand this implementation in C of the Dijkstra algorithm and at the same time modify it so that only the shortest path between 2 specific nodes (source and destination) is found. However, I don't know exactly what do to. The way I see it, there's nothing much to do, I can't seem to change d[] or prev[] cause those arrays aggregate some important data for the shortest path calculation. The only thing I can think of is stopping the algorithm when the path is found, that is, break the cycle when mini = destination when it's being marked as visited. Is there anything else I could do to make it better or is that enough? P.S: I just noticed that the for loops start at 1 until <=, why can't it start at 0 and go until <?

    Read the article

  • Bejeweled Blitz - How does it assert there is always a move?

    - by EvilTeach
    I have been playing Bejeweled Blitz for a while now. Yes, it is an addiction. In thinking about the game, I have observed that on some boards, the bottom runs dry (no moves) leaving only the top part of the board playable. Frequently that part of the board drys up, and one is left with moves in area cleared by the last move. The board never runs completely dry, so clearly the program is doing some sorts of calculation that allows it to choose what to drop to prevent it from running dry. I have noticed in this 'mode' that it is very common for the algorithm to drop jewels which causes more non-dry area to appear in the horizontal area. Perhaps less frequent is a drop which seems designed to open up the bottom part of the board again. So my question is "How would one go about designing an algorithm guarantee that there is always a move available.?"

    Read the article

  • postgresql weighted average?

    - by milovanderlinden
    say I have a postgresql table with the following values: id | value ---------- 1 | 4 2 | 8 3 | 100 4 | 5 5 | 7 If I use postgresql to calculate the average, it gives me an average of 24.8 because the high value of 100 has great impact on the calculation. While in fact I would like to find an average somewhere around 6 and eliminate the extreme(s). I am looking for a way to eliminate extremes and want to do this "statistically correct". The extreme's cannot be fixed. I cannot say; If a value is over X, it has to be eliminated. I have been bending my head on the postgresql aggregate functions but cannot put my finger on what is right for me to use. Any suggestions?

    Read the article

  • Why can't I share a variable between two content sections in an ASP.NET MVC View?

    - by Dave Van den Eynde
    I have an ASP.NET MVC View with the typical TitleContent and MainContent, with a fairly complicated title that I want to calculate once and then share between these two content sections, like so: <%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <% var complicatedTitle = string.Format("{0} - {1}", Model.FirstThing, Model.SecondThing); %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> <%: complicatedTitle %> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2><%: complicatedTitle %></h2> </asp:Content> This, however, doesn't work, as the resulting error message would say that only Content controls are allowed directly in a content page that contains Content controls. The calculation definately belongs in the view. How do you solve this problem?

    Read the article

  • add new column in birt report based on generated grand total column in crosstab

    - by Sanga
    Hi there, Thanks for reading my question. Please I need your help here. I am trying to add a column that is based on a cross-tab's grand total. The cross-tab was added by clicking on the totals option for the column. Now I want to use this total for another calculation in my cross-tab but its so difficult adding a column after the grand total column. Secondly its difficult getting a reference to the results in the grand total column. Please what do you advice? Thanks Ime

    Read the article

  • Binomial test in Python

    - by Morlock
    I need to do a binomial test in Python that allows calculation for 'n' numbers of the order of 10000. I have implemented a quick binomial_test function using scipy.misc.comb, however, it is pretty much limited around n = 1000, I guess because it reaches the biggest representable number while computing factorials or the combinatorial itself. Here is my function: from scipy.misc import comb def binomial_test(n, k): """Calculate binomial probability """ p = comb(n, k) * 0.5**k * 0.5**(n-k) return p How could I use a native python (or numpy, scipy...) function in order to calculate that binomial probability? If possible, I need scipy 0.7.2 compatible code. Many thanks!

    Read the article

  • Excel 2007 Visual Basic Editor: eats spaces, throws cursor around

    - by Vincent
    I can't resolve this issue, I found a similar question here but: setting the workbook to Manual calculation (alt-m-x-m or alt-t-oformulas) didn't work Setting editor options to disable: Auto syntax check & Background compile didn't work anybody have any idea how to fix this very annoying behaviour, I'm used to quickly pop up VBA (alt-f11), f7 to get into code and write some quick procedures there... and it's hard to get out of that habit, I don't want to write any office extension to just add a single quote to every cell in the range For Each rg In Selection rg = chr(39) & rg.value Next F5, done...

    Read the article

  • Drag Rotate UIImageView by touch

    - by rockstardev
    I have an UIImageView that is a subview of an UIView. I'm trying to create a drag rotate effect with the UIImageView similar to spinning a bottle but I'm having trouble calculating the radians to rotate the image by. My code below seems like it should work because I've seen a similar calculation in Flash examples. Can anyone shed some light on what I'm doing wrong? Thanks. This is the code contained in my image view subclass: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; lastLocation = [touch locationInView:[self superview]]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [[event allTouches] anyObject]; CGPoint location = [touch locationInView:[self superview]]; CGFloat xDisplacement = location.x - lastLocation.x; CGFloat yDisplacement = location.y - lastLocation.y; CGFloat rad = atan2f(yDisplacement,xDisplacement); self.transform = CGAffineTransformMakeRotation(rad); }

    Read the article

  • What is going on with the "return fibonacci( number-1 ) + fibonacci( number-2 )"?

    - by user1478598
    I have problem understanding what the return fibonacci( number-1 ) + fibonacci( number-2 ) does in the following program: import sys def fibonacci( number ): if( number <= 2 ): return 1 else: return fibonacci( number-1 ) + fibonacci( number-2 ) The problem is that I can't imagine how this line works: return fibonacci( number-1 ) + fibonacci( number-2 ) Does the both of the "fibonacci( number-1 )" and "fibonacci( number-2 )" being processed at the same time? or the "fibonacci( number-1 )" is the first to be processed and then the second one? I only see that processing both of them would eventually return '1' so the last result I expect to see it is a '1 + 1' = '2' I would appreciate a lot, If someone can elaborately explain the process of its calculation. I think this is a very newb question but I can't really get a picture of its process.

    Read the article

  • .NET Data Adapter Timeout SP Issue

    - by A-B
    We have a SQL Server stored procedure that runs fine in SQL Manager directly, does a rather large calculation but only takes 50-10 seconds max to run. However when we call this from the .NET app via a data adapter it times out. The timeout however happens before the timeout period should, we set it to 60 seconds and it still times out in about 20 seconds or less. I've Googled the issue and seen others note issues where a SP works fien directly but is slow via a data adpater call. Any ideas on how to resolve this?

    Read the article

  • Need a formula for calculating the tax portion of a total amount.

    - by pawz
    In Australia we have to advertise products with tax already added, so rather than say a product is $10 + $1 GST = $11, we normally work backwards and say "ok, total is $10, how much of that is GST ?" For example, for a $10 total, you do 10 * (1 /11) = 0.91, which is the tax component of the $10 total. My problem is I need calculate a formula for working out the taxable component when the tax rate is a variable. So far I've made this calculation although I'm not sure how correct an assertion it is: 10 * (1 / x) = 0.09 * (1 / y) where y = 10, x = 11 Basically i want to work out x on the left hand side when I know that the tax rate is 0.05 for example, which will give me a formula that I can use to calculate the taxable component of an total figure. I want a function into which I can plug in the total price and the tax rate, and get back the taxable component of the total price. I'd really appreciate the help with this as it really makes my head hurt ! :")

    Read the article

  • Access to selection in gmail message body with Google Apps Script

    - by Mike Ellis
    Can app scripts access the current selection in a gmail message? I frequently compose messages that include engineering calculations and make use of the Google Calc feature do the calculation or convert to the desired units, e.g. 4000 Btu/hr * 8 hrs in kWh It would be really convenient to be able to select the above, hit a mapped key (e.g. Ctrl-K) and have the inserted after the expression 4000 Btu/hr * 8 hrs in kWh = 0.9378 kWh instead of having to paste the expression into a search box and then copy and paste the answer. I could certainly write a solution using a keymapper and a small python script to grab the current selection, send it to the gcalc api, etc ..., but my real motivation is to get familiar with Apps Scripts's capabilities and limitations. I suppose the uber-question here is "what kinds of user actions and state information can App Script access in Gmail messages (and/or Google docs) that are being edited?"

    Read the article

  • Console appliction with Multithreading on Single core.

    - by Harsha
    Hello all, I am reposting my question on Multithreading on Single core processor. Original question is: http://stackoverflow.com/questions/2856239/will-multi-threading-increase-the-speed-of-the-calculation-on-single-processor I have been asked a question, At any given time, only one thread is allowed to run on a single core. If so, why people use multithreading in a application. Lets say you are running console application and It is very much possible to write the application to run on the main thread. But still people go for multithreading.

    Read the article

  • How can I call model methods or properties from Django Admin?

    - by kg
    Is there a natural way to display model methods or properties in the Django admin site? In my case I have base statistics for a character that are part of the model, but other things such as status effects which affect the total calculation for that statistic: class Character(models.Model): base_dexterity = models.IntegerField(default=0) @property def dexterity(stat_name): total = self.base_dexterity total += sum(s.dexterity for s in self.status.all()]) return total It would be nice if I could display the total calculated statistic alongside the field to change the base statistic in the Change Character admin page, but it is not clear to me how to incorporate that information into the page.

    Read the article

  • pyplot: really slow creating heatmaps

    - by cvondrick
    I have a loop that executes the body about 200 times. In each loop iteration, it does a sophisticated calculation, and then as debugging, I wish to produce a heatmap of a NxM matrix. But, generating this heatmap is unbearably slow and significantly slow downs an already slow algorithm. My code is along the lines: import numpy import matplotlib.pyplot as plt for i in range(200): matrix = complex_calculation() plt.set_cmap("gray") plt.imshow(matrix) plt.savefig("frame{0}.png".format(i)) The matrix, from numpy, is not huge --- 300 x 600 of doubles. Even if I do not save the figure and instead update an on-screen plot, it's even slower. Surely I must be abusing pyplot. (Matlab can do this, no problem.) How do I speed this up?

    Read the article

< Previous Page | 46 47 48 49 50 51 52 53 54 55 56 57  | Next Page >