primitive-types

how do I initialize a float to its max/min value?

How do I hard code an absolute maximum or minimum value for a float or double? I want to search out the max/min of an array by simply iterating through and catching the largest. There are also positive and negative infinity for floats, should I use those instead? If so, how do I denote that in my code? ...

Java - short and casting

Hi all, I have the following code snippet. public static void main(String[] args) { short a = 4; short b = 5; short c = 5 + 4; short d = a; short e = a + b; // does not compile (expression treated as int) short z = 32767; short z_ = 32768; // does not compile (out of range) test(a); test(7); // does not compile (not applica...

Efficiency of Java code with primitive types

Hello! I want to ask which piece of code is more efficient in Java? Code 1: void f() { for(int i = 0 ; i < 99999;i++) { for(int j = 0 ; j < 99999;j++) { //Some operations } } } Code 2: void f() { int i,j; for(i = 0 ; i < 99999;i++) { for(j = 0 ; j < 99999;j++) { //Some operations } } } My teacher said tha...

Storage requirements of primitive types in Win x64

For either List with n elements, which (if any) requires more storage on x64 machine: List<int> -or- List<long> I guess the question can be rephrased as: On x64, does an int take any less space than a long? ...

Generics syntax: classes versus primitive data types

Why does this one does not work: ArrayList<LinkedList<int>> where this one does: ArrayList<LinkedList<Integer>> ??? ...

About long long and long double

Since when have they been part of standard C++? I think long long is a C++0x feature, is that right? What about long double? Was that already in C++98 or C++03? ...

Why is it that an int in C++ that isnt initialized (then used) doesn't return an error?

I am new to C++ (just starting). I come from a Java background and I was trying out the following piece of code that would sum the numbers between 1 and 10 (inclusive) and then print out the sum: /* * File: main.cpp * Author: omarestrella * * Created on June 7, 2010, 8:02 PM */ #include <cstdlib> #include <iostream> using name...

Calling Java vararg method from Scala with primitives

I have the following code in Java: public class JavaClass { public static void method( Object x ) { } public static void varargsMethod( Object... x ) { } } When I try and access it from Scala, object FooUser { JavaClass.method(true) JavaClass.varargsMethod(true) // <-- compile error } I get the following comp...

When to use primitives in Objective-C?

When should I use primitives in Objective-C instead of NSValue subclasses? This code is certainly cleaner (I think) than using NSNumber: float width = sliderOne.frame.size.width; float totalWidth = width * 2 + 10; but are there any drawbacks? Also, is it correct that I don't need to call release or anything with primitives? Do...

C++ variant for Java long?

Is there a C++ variant for the long primitive data-type? A C++ long is only 4 bytes, while a Java long is 8 bytes. So: Is there a non-decimal primitive type with a size of 8 bytes in C++? Maybe with some tricks? Thanks ...

Why does wrapper classes for primitive data types don't have a setter ?

What is the reason why Wrapper classes (like Integer, Double, etc.) don't have a setter for their inner primitive value ? I am asking this because that kind of functionality would have simplified calculus, and have made the Java language a little more flexible . Let me give you some examples. 1) Let's take the following example: Int...

Java primitive collections library

What is the best Java primitive collections library? (most memory and time efficient) I've found Trove and FastUtil to be the most used ones, but haven't found much comparison between them (or between others) Is there any comparison available? ...

java multi thread access to primitive variables

Hi - I know that concurrently accessing the same object from different threads, without synchronisation, is in general a bad thing. But what about this case: I have multiple threads running (consider two, ThreadA & ThreadB). I also have this static class to keep count of the number of times a Thread does something. public class Counter...

Extending primitive types

Is it possible to extend primitive types such as System.String and System.Int32 (IE: integer) in .Net 4 and if so how? To be more specific, I am aware of the concept of partial classes but this doesnt seem to be the answer. Also I find that System.String is not inheritable and Int32 is a structure. Lastly I am interested in knowing bot...

Converting a byte array to an array of primitive types with unknown type in C#

Hello, I have the following problem. I have an array of bytes that I want to convert intro an array of primitive types. But I don't know the type. (This is given as an array of types). As a result I need an array of objects. Of course I could use a switch on the types (there are only a limited number of them), but I wonder if there is ...

System.Int32 contains... another System.Int32

Hey guys, I thought about writing a language for the sake of writing a language, and now that I'm done with the parser and the AST, I have to do something about the library. Specifically, basic types. I'm going to use a very basic intermediate representation before I pass that down to LLVM and get native code that way. Though, since my...

Is it possible to map collections of primitive types with EF4?

Is there a way to map a collection/dictionary of primitive types in Entity Framework. I would like to have: public class Abc { public virtual long Id {get;set;} public virtual ... some properties public virtual IList<float> Numbers; // or even: public virtual IDictionary<DateTime,decimal> MoreNumbers; ...

Why do I get "Invalid receiver type 'NSInteger'"?

Probably a simple question: Why do I get an compiler warning for the following objective-C code? //_classificationView.tag is a NSString CGFloat imageWidth = [_classificationView.tag floatValue] * 14.0; And why does it say something about NSInteger? Thanks for answers! Dennis ...

Numeric value of digit characters in C

I have just started reading through The C Programming Language and I am having trouble understanding one part. Here is an excerpt from page 24: #include<stdio.h> /*countdigits,whitespace,others*/ main() { intc,i,nwhite,nother; intndigit[10]; nwhite=nother=0; for(i=0;i<10;++i) ndigit[i]=0; while((c=getchar())!=EOF) ...

Why is string a reference type?

Why is string a reference type, even though it's normally primitive data type such as int, float, or double. ...