int64

std::atoll with VC++

▼魔方 西西 提交于 2019-12-06 21:44:33
问题 I have been using std::atoll from cstdlib to convert a string to an int64_t with gcc. That function does not seem to be available on the Windows toolchain (using Visual Studio Express 2010). What is the best alternative? I am also interested in converting strings to uint64_t . Integer definitions taken from cstdint . 回答1: MSVC have _atoi64 and similar functions, see here For unsigned 64 bit types, see _strtoui64 回答2: use stringstreams ( <sstream> ) std::string numStr = "12344444423223"; std:

Multiplying __int64's

有些话、适合烂在心里 提交于 2019-12-05 13:22:41
Can someone explain to me (in detail) how to multiply two __int64 objs and check if the result will fit in __int64. Note: Do not use any compiler or processor dependent routines. not assuming a and b are positive: __int64 a,b; //... __int64 tmp_result = abs(a) * abs(b) ; if ( ( a && b ) && ( ( tmp_result < abs(a) || tmp_result < abs(b) ) || ( tmp_result / abs(a) != abs(b)) || ( a == TYPE_MIN && b != 1) || ( b == TYPE_MIN && a != 1) ) ) std::cout << "overflow"; __int64 result = a * b; EDIT: Adding corner cases to code. EDIT: In my opinion just ( a && a * b / a != b) is enough. 来源: https:/

What is the int.MaxValue on a 64-bit PC?

柔情痞子 提交于 2019-12-05 11:49:15
问题 System.Console.WriteLine(int.MaxValue); This line gives me the answer of 2,147,483,647 as I have a 32-bit PC. Will the answer be same on a 64-bit PC? 回答1: Yes. int.MaxValue: 2,147,483,647 Source: https://www.dotnetperls.com/int-maxvalue 回答2: Yes, the answer will be the same on a 64-bit machine. In .NET, an int is a signed 32-bit integer, regardless of the processor. Its .NET framework type is System.Int32 . The C# Language specification states: The int type represents signed 32-bit integers

Is it ok to use 64bit integers in a 32bit application?

帅比萌擦擦* 提交于 2019-12-05 04:07:35
I notice in C and C++, we can use int64_t , or simply a long long . If I compile 32bit code using these types, will I suffer any performance issues on 64bit and/or 32bit machines ? Aside from saving some RAM, would I ever have a reason to just use int ? After all, 64bit ints are far more useful in storing large numbers. If I compile 32bit code using these types, will I suffer any performance issues on 64bit and/or 32bit machines? Your compiler may need to generate several machine code instructions to perform operations on the 64 bit values, slowing down those operations by several times. If

std::atoll with VC++

别说谁变了你拦得住时间么 提交于 2019-12-05 01:36:22
I have been using std::atoll from cstdlib to convert a string to an int64_t with gcc. That function does not seem to be available on the Windows toolchain (using Visual Studio Express 2010). What is the best alternative? I am also interested in converting strings to uint64_t . Integer definitions taken from cstdint . MSVC have _atoi64 and similar functions, see here For unsigned 64 bit types, see _strtoui64 use stringstreams ( <sstream> ) std::string numStr = "12344444423223"; std::istringstream iss(numStr); long long num; iss>>num; use boost lexical_cast ( boost/lexical_cast.hpp ) std::string

How can I print out an constant uint64 in Go using fmt?

点点圈 提交于 2019-12-04 17:10:13
问题 I tried: fmt.Printf("%d", math.MaxUint64) but I got the following error message: constant 18446744073709551615 overflows int How can I fix this? Thanks! 回答1: math.MaxUint64 is a constant, not an int64. Try instead: fmt.Printf("%d", uint64(num)) The issue here is that the constant is untyped. The constant will assume a type depending on the context in which it is used. In this case, it is being used as an interface{} so the compiler has no way of knowing what concrete type you want to use. For

What is the int.MaxValue on a 64-bit PC?

十年热恋 提交于 2019-12-03 23:34:27
System.Console.WriteLine(int.MaxValue); This line gives me the answer of 2,147,483,647 as I have a 32-bit PC. Will the answer be same on a 64-bit PC? Unknown Yes. int.MaxValue: 2,147,483,647 Source: https://www.dotnetperls.com/int-maxvalue Daniel LeCheminant Yes, the answer will be the same on a 64-bit machine. In .NET, an int is a signed 32-bit integer , regardless of the processor. Its .NET framework type is System.Int32 . The C# Language specification states: The int type represents signed 32-bit integers with values between –2,147,483,648 and 2,147,483,647 . int is just an alias for Int32

How can I print out an constant uint64 in Go using fmt?

喜欢而已 提交于 2019-12-03 11:03:48
I tried: fmt.Printf("%d", math.MaxUint64) but I got the following error message: constant 18446744073709551615 overflows int How can I fix this? Thanks! math.MaxUint64 is a constant, not an int64. Try instead: fmt.Printf("%d", uint64(num)) The issue here is that the constant is untyped. The constant will assume a type depending on the context in which it is used. In this case, it is being used as an interface{} so the compiler has no way of knowing what concrete type you want to use. For integer constants, it defaults to int . Since your constant overflows an int, this is a compile time error.

How to convert tf.int64 to tf.float32?

冷暖自知 提交于 2019-12-03 09:42:44
I tried: test_image = tf.convert_to_tensor(img, dtype=tf.float32) Then following error appears: ValueError: Tensor conversion requested dtype float32 for Tensor with dtype int64: 'Tensor("test/ArgMax:0", shape=TensorShape([Dimension(None)]), dtype=int64)' You can cast generally using: tf.cast(my_tensor, tf.float32) Replace tf.float32 with your desired type. Edit : It seems at the moment at least, that tf.cast won't cast to an unsigned dtype (e.g. tf.uint8 ). To work around this, you can cast to the signed equivalent and used tf.bitcast to get all the way. e.g. tf.bitcast(tf.cast(my_tensor, tf

Swift: Cast Any Object to Int64 = nil

a 夏天 提交于 2019-12-01 18:59:04
i have a question. I was wondering why this is happend? var dict : [String : Any] = ["intValue": 1234, "stringValue" : "some text"] dict["intValue"] as? Int64 // = nil (why) dict["intValue"] as? Int // = 1234 can anybody tell me why the cast to Int64 returns nil? Edited part: I have simplify my question, but i think this was not a good idea. :) In my special case I will get back a Dictionary from a message body of WKScriptMessage. I know that in one field of the Dictionary there is a Int value that can be greater than Int32. So if I cast this value to Int it will works on 64-bit systems. But