computer-science

Using float / double as a loop variable

坚强是说给别人听的谎言 提交于 2019-12-13 03:45:01
问题 Running on a x64 architecture , Visual Studio 2013 Windows 8.1 I am trying to run a loop which uses a float as its loop variable , the issue is during the increment operation the decimal values are being lost . Eg : float incrementValue = 360 / 14; for (float i = 0; i <= 360; i = i + incrementValue) { cout << endl << " I " << i; } I need the value of i >= 360 . But it stops at 350 . Since 360/14 =25.7142857 but looks like the increments are in steps of 25 . If i do the same thing with any

How can I fix Encoding in tweepy?

谁都会走 提交于 2019-12-13 01:47:47
问题 I'm working on tweety module and I tried this code for taking tweet by written Turkish(in turkish language,some charecter doesn't support ascii such as ğ,ş,ö,ç,İ,ı) but I need clearly whole data. from tweepy import Stream from tweepy import OAuthHandler from tweepy.streaming import StreamListener import time ckey = "****" csecret = "****" atoken = "****" asecret = "****" class listener(StreamListener): def on_data(self,data): tweet = data.split(',"text":"')[1].split('","source')[0] print

Duplicating characters using sed

六眼飞鱼酱① 提交于 2019-12-13 01:37:21
问题 This question was migrated from Mathematics Stack Exchange because it can be answered on Stack Overflow. Migrated 4 years ago . I am working on trying to duplicate characters on certain words, but the sed script I wrote is not quite doing what I want it to. For example, I am trying to duplicate each character in a words like so: FILE into FFIILLEE I know how to remove the duplicate letters with : sed s/\(.\)\1/\1/g' file.txt This is the sed script I wrote, but it just ends up duplicating the

Is a single constant value considered an expression?

非 Y 不嫁゛ 提交于 2019-12-12 20:17:14
问题 After reading this answer on a CSS question, I wonder: In Computer Science, is a single, constant value considered an expression? In other words, is 7px an expression? What about just 7 ? Quoting Wikipedia, emphasis mine: An expression in a programming language is a combination of one or more explicit values , constants, variables, operators, and functions that the programming language interprets [...] and computes to produce [...] another value . This process, as for mathematical expressions

How to fix this floating point square root algorithm

给你一囗甜甜゛ 提交于 2019-12-12 18:10:37
问题 I am trying to compute the IEEE-754 32-bit Floating Point Square Root of various inputs but for one particular input the below algorithm based upon the Newton-Raphson method won't converge, I am wondering what I can do to fix the problem? For the platform I am designing I have a 32-bit floating point adder/subtracter, multiplier, and divider. For input 0x7F7FFFFF (3.4028234663852886E38)., the algorithm won't converge to the correct answer of 18446743523953729536.000000 This algorithm's answer

Representing intervals or ranges? [closed]

╄→гoц情女王★ 提交于 2019-12-12 12:10:32
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 2 years ago . In general, whenever you're representing a range of any kind, you have several choices for what kinds of values to choose for the beginning and ending of your range. For example, if you want to have a range containing the integers 1, 2, 3, 4, 5 you could choose these possible

How exactly does dp parameter in cv::HoughCircles work?

此生再无相见时 提交于 2019-12-12 10:05:33
问题 I read similar question in Stack Overflow. I tried, but I still can not understand how it works. I read OpenCV document cv::HoughCircles, here are some explanation about dp parameter: Inverse ratio of the accumulator resolution to the image resolution. For example, if dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has half as big width and height. Here are my question. For example, if dp = 1, the size of accumulator is same as image, there is a

Find row of pyramid based on index?

蓝咒 提交于 2019-12-12 09:42:42
问题 Given a pyramid like: 0 1 2 3 4 5 6 7 8 9 ... and given the index of the pyramid i where i represents the i th number of the pyramid, is there a way to find the index of the row to which the i th element belongs? (e.g. if i = 6,7,8,9 , it is in the 3rd row, starting from row 0) 回答1: There's a connection between the row numbers and the triangular numbers. The nth triangular number, denoted T n , is given by T n = n(n-1)/2. The first couple triangular numbers are 0, 1, 3, 6, 10, 15, etc., and

Why .Net dictionaries resize to prime numbers?

删除回忆录丶 提交于 2019-12-12 09:33:24
问题 According to this question a .Net dictionary resizes its allocated space to prime numbers that are at least twice the current size. Why is it important to use prime numbers and not just twice the current size? (I tried to use my google-fu powers to find an answer, but to no avail) 回答1: It is an algorithm implementation detail related to choosing a good hashing function and which provides uniform distribution. A non-uniform distribution increases the number of collisions, and the cost of

What are futures?

风流意气都作罢 提交于 2019-12-12 07:47:00
问题 What are futures? It's something to do with lazy evaluation. 回答1: There is a Wikipedia article about futures. In short, it's a way to use a value that is not yet known. The value can then be calculated on demand (lazy evaluation) and, optionally, concurrently with the main calculation. C++ example follows. Say you want to calculate the sum of two numbers. You can either have the typical eager implementation: int add(int i, int j) { return i + j; } // first calculate both Nth_prime results