numbers

Negative values returned from file in NXC

痞子三分冷 提交于 2019-12-04 05:48:00
问题 I am saving values to a .csv file in NXC(Not eXactly C) and then calling on them ata later point in time. The problem I am having is when calling any negative values back from a cell it is displayed as 0123 instead of -123 which is throwing all my additional calculations off. The current code is: OpenFileRead("map.csv", fSize, count); until (eof == true) { ReadLnString(count, val); int lstFwd = StrToNum(val); NumOut(0,LCD_LINE1,lstFwd); } while(true); Can anyone explain how to rectify this

What's algorithm used to solve Linear Diophantine equation: ax + by = c

帅比萌擦擦* 提交于 2019-12-04 05:32:38
问题 I'm looking for integers solution here. I know it has infinitely many solution derived from the first pair solution and gcd(a,b)|c. However, how could we find the first pair of solution? Is there any algorithm to solve this problem? Thanks, Chan 回答1: Note that there isn't always a solution. In fact, there's only a solution if c is a multiple of gcd(a, b) . That said, you can use the extended euclidean algorithm for this. Here's a C++ function that implements it, assuming c = gcd(a, b) . I

Round a number to the next HIGHEST 10

只谈情不闲聊 提交于 2019-12-04 05:10:19
I have a need to create a graph, where the scale of the Y-axis changes depending on the data input into the system. Conceivably this scale could be anywhere from 0-10, 0-100, or even have bottom limit of thousands and an upper limit of millions. To properly determinethe scale of this axis, I need to work out the ratio of Points to Pixels (based on graph height/range). Now a graphs' axis never start at the lowest value and go to the highest, usual practice is to go to the next nearest 2, 5 or 10 (above for upper limit, and below for lower) depending on the range of values. So what I'd like to

Get true or false with a given probability

痴心易碎 提交于 2019-12-04 04:53:33
I'm trying to write a function in c++ that will return true or false based on a probability given. So, for example if the probability given was 0.634 then, 63.4% of the time the function would return true. I've tried a few different things, and failed. Any help? If you'd like to do this in C++11, you can use its various random number engines, combined with the uniform_real_distribution to provide a good result. The following code demonstrates: #include <random> std::knuth_b rand_engine; // replace knuth_b with one of the engines listed below std::uniform_real_distribution<> uniform_zero_to_one

Get a list of numbers from range(s) of number

倾然丶 夕夏残阳落幕 提交于 2019-12-04 04:43:08
问题 I have a data frame where one column contains a range (or ranges) of numbers. I would like to turn this into a list of numbers based of the given range. Example input: "35-40" or "35-43, 45-47" This should yield: [1] 35 36 37 38 39 40 and [1] 35 36 37 38 39 40 41 42 43 45 46 47 回答1: We can do a split and with Map , get the numbers do.call(Map, c(`:`, lapply(strsplit(df1$v1, '-'), as.numeric))) #[[1]] # [1] 35 36 37 38 39 40 41 42 43 44 45 #[[2]] #[1] 43 44 45 46 47 If we need to find the

Convert scientific notation to decimal notation

眉间皱痕 提交于 2019-12-04 04:26:06
问题 There is a similar question on SO which suggests using NumberFormat which is what I have done. I am using the parse() method of NumberFormat. public static void main(String[] args) throws ParseException{ DecToTime dtt = new DecToTime(); dtt.decToTime("1.930000000000E+02"); } public void decToTime(String angle) throws ParseException{ DecimalFormat dform = new DecimalFormat(); //ParsePosition pp = new ParsePosition(13); Number angleAsNumber = dform.parse(angle); System.out.println(angleAsNumber

parse long to negative number

元气小坏坏 提交于 2019-12-04 04:14:55
问题 code: public class Main{ public static void main(String[] a){ long t=24*1000*3600; System.out.println(t*25); System.out.println(24*1000*3600*25); } } This prints : 2160000000 -2134967296 Why? Thanks for all the replies. Is the only way to use L after the number? I have tried the (long)24*1000*3600*25 but this is also negative. 回答1: To explain it clearly, System.out.println(24*1000*3600*25); In the above statement are actually int literals. To make treat them as a long literal you need to

REGEX To accept numbers separated by commas, but number range is 0-32767

自闭症网瘾萝莉.ら 提交于 2019-12-04 03:48:39
I need to write a regular expression for taking input like this 23,456,22,1,32767 i.e. No commas allowed at the start or end. Spaces may come before and/or start of comma for e.g. 23, 45,56 ,67 etc. Ranges of each number should be 0-32767. Currently I am using regular expression like this [0-9]+(,[0-9]+)* . This allows for numbers separated by commas only ( not allowing spaces at all), and it does not check for the range of number. It's probably wise to do it in two steps. First check that the range is 0-99999: ^[0-9]{1,5}( *, *[0-9]{1,5})*$ Then parse the string to a list of integers using a

Can I tell if a std::string represents a number using stringstream?

倖福魔咒の 提交于 2019-12-04 03:36:12
Apparently this is suposed to work in showing if a string is numerical, for example "12.5" == yes, "abc" == no. However I get a no reguardless of the input. std::stringstream ss("2"); double d; ss >> d; if(ss.good()) {std::cout<<"number"<<std::endl;} else {std::cout<<"other"<<std::endl;} You should use an istringstream so that it knows it's trying to parse input. Also, just check the result of the extraction directly rather than using good later. #include <sstream> #include <iostream> int main() { std::istringstream ss("2"); double d = 0.0; if(ss >> d) {std::cout<<"number"<<std::endl;} else

Spreadsheets: how do I SUM values in a column, only if the text column has a 1?

半城伤御伤魂 提交于 2019-12-04 03:33:14
问题 Let's say I have this data 4 1 4 0 4 1 3 0 5 1 How do I write a function (using SUM or something like that) to add all the values on the left, if the values on the right are 1, or true The total should be 13 回答1: Assuming columns A and B are used... Check just for 1: =SUMIF(B1:B5,"=1",A1:A5) If you want to check for TRUE also: =SUMIF(B1:B5,"=1",A1:A5) + SUMIF(B1:B5,"=TRUE",A1:A5) 回答2: sort by column b, then auto-sum the values you want in column a. cheap & lazy solution. 来源: https:/