Overloading Multiply Two Numbers - operator-overloading

Write a java class that has separate methods to multiply two numbers of different data types. This class should share the same name for the different methods which are adding two numbers of differnt data types
This class should have some methods so that you can add two
Integer numbers
Float & integer
Integer & float
Double & integer
Integer & double
Float & double
Double & float
Double & double
Float & float
with the same name
All above methods should accept two parameters (of different data types and should return the answer
after that write a proper driver class to test all the methods
hint: use method over loading techniques

Related

storing decimal into pgtype numeric

I was working with pgtype.NumRange. The lower and upper bounds are typed pgtype.Numeric. pgtype.Numeric has the following fields
type Numeric struct {
Int *big.Int
Exp int32
Status Status
NaN bool
InfinityModifier InfinityModifier
}
I guess I'm suppose to able to represent any number using the duo of the Int and Exp fields, but I don't know how to, as big.Int and `int32' are integer types.
From Postgres docs, I can see that numrange can take decimal values in any of lower and upper bounds and data type numeric is a superset of decimal type. So I know I should be able to use decimals, but
how can I go about this?

long long constant number in swift

I'm looking Swift alias for Objective-C constant long long int and float numbers.
That is, how can this : 1000LL and .1f be converted into Swift code?
No information found here:
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html
You use as-casting when you need to specify literal types in Swift.
1000LL -> 1000 as Int64
.1f -> 0.1 as Float

How to store a price in two integers in swift

I have read that I shouldn't treat prices as double numbers and that I should store them as two integers.
If for example I have an input of type 246.464 in a UITextField how should I make it two integers?
Forget two integers, store it as NSDecimalNumber. That's the class specifically created for that task.
Unlike float or double, NSDecimalNumber uses decadic arithmetic therefore there is no loss in precision when converting between decadic to binary and viceversa.
let text = "246.464" // textField.text
let number = NSDecimalNumber(string: text)

How to make a simple division of Double by Int in Swift?

Looking at various posts on this topic but still no luck. Is there a simple way to make division/conversion when dividing Double (or Float) with Int? Here is a simple example in playground returning and error "Double is not convertible to UInt8".
var score:Double = 3.00
var length:Int = 2 // it is taken from some an array lenght and does not return decimal or float
var result:Double = (score / length )
Cast the int to double with var result:Double=(score/Double(length))
What this will do is before computing the division it will create a new Double variable with int inside parentheses hence constructor like syntax.
You cannot combine or use different variable types together.
You need to convert them all to the same type, to be able to divide them together.
The easiest way I see to make that happen, would be to make the Int a Double.
You can do that quite simply do that by adding a ".0" on the end of the Integer you want to convert.
Also, FYI:
Floats are pretty rarely used, so unless you're using them for something specific, its also just more fluid to use more common variables.

float arrays in objective C

Do I need to null-terminate a basic float array in objective C?
I have a basic float array:
float data[] = {0.5, 0.1, 1};
and when I do a sizeof(data) I get "12".
You don't need to null terminate it to create one, no. And in general a method taking a float[] would also take a size parameter to indicate how many elements there are.
You get sizeof(data) = 12 because a float is 4-bytes on your architecture and there's 3 of them.
sizeof return the amount of memory (in bytes) occupied by the parameter. In your case, every float occupies 4 bytes, thus 4*3=12.
As Hot Licks said in the comment of mattjgalloway's answer, there is not a standard way to retrieve the number of elements in a C array.
Using size = sizeof(data) / sizeof(float) works, but you must be careful in using this approach, since if you pass the array as a parameter it won't work.
A common approach is to store the size in a variable and use it as upper bound in your for loop (often functions that expect an array have an additional parameter to get the size of the array).
Using a null-terminated array is useful because you can iterate through your array and stop when the i-esim element is null (that's the approach of methods like strcmp).
Values of type float can never be null, so it's not possible to terminate an array of type float with null. For one thing, variables of any primitive type always have a numeric value, and the various null constants (in Objective-C nil, Nil, NULL, and '\0') have the literal value 0, which is obviously a valid value in range of a float.
So even if you can compile the following line without a warning,
float x = NULL;
...it would have the same consequence as this:
float x = 0;
Inserting a null constant in an array of type float would be indistinguishable from inserting 0.0 or any other constant zero value.