Is 5dp same as 5.0dp? - android-layout

Reading android code I find out is not uncommon to fill the xml with the second variant, like here.
To be honest, this alone would be enough for my head to torment me with the question, but then I see code in which the two notations are even mixed, like in this StackOverflow question.
Google wasn't of help, and I couldn't find this question on SO.
Anyone knows what's the difference, if any?
EDIT
Based on the firsts question I got here, there seems to be no improvement in performance or other things like that when using the second variant, so writing them as float when they can be integers just tells people they can insert decimal values in there. Anything else?
If that's the only reason, I think using the second option it's just like polluting the xml for little to no reason, are there other opinions?

Check out this link: http://developer.android.com/guide/topics/resources/more-resources.html#Dimension. It shows the possible values for dimensions. They are all floats. So, you can write them either way.

The 5.0 version is because certain properties accept a float/double value. All in all, 5.0 is the same as 5 when DP are involved.

one is an int the other is a float. They are types of primitives

It is the same. They both have the same values. 5 and 5.0 are of different types. 5 is of type int and 5.0 is of type float/double.

Related

PySCIPOpt/SCIP - Branching/Separation with fractional variable

I began using PySCIPOpt/SCIP for a Coursera course on discrete optimization. I'd need to implement a simple separation from a fractional variable and wonder how to do it. Online SCIP literature does not provide relevant example.
Any Python example for me to get inspired for my assignment?
Thank you for the answer. Indeed I spent some hours reading SCIP documentation and I have trouble interfacing SCIp methods in Python.
I have been able to implement in Python a simple constraint handler to add first-type cuts and I'd like to add a separator to add second-type cuts.
The latter cuts are typically x = 0 or 1 cuts based on fractional x values and I stumble more with syntax - addCut() - and using generic methods than the process itself.
A Python example, a bit more involved than tsp.py, would greatly help me.
Your question is quite broad. I try to give some hints on where to look for an answer:
general information on separators in SCIP
difference between constraint handlers and separators
Python example on a separator implemented as constraint handler to solve the Traveling Salesman Problem
I can try to answer your question more precisely, if you explain your application/problem in more detail.

Does Julia have a way to solve for unknown variables

Is there a function in Julia that is similar to the solver function in Excel where I can provide and equation, and it will solve for the unknown variable? If not, does anybody know the math behind Excel's solver function?
I am not expecting anybody to solve the equation, but if it helps:
Price = (Earnings_1/(1+r)^1)+(Earnings_2/(1+r)^2)++(Earnings_3/(1+r)^3)+(Earnings_4/(1+r)^4)+(Earnings_5/(1+r)^5)+(((Earnings_5)(RiskFreeRate))/((1+r)^5)(1-RiskFreeRate))
The known variables are: Price, All Earnings, and RiskFreeRate. I am just trying to figure out how to solve for r.
Write this instead as an expression f(r) = 0 by subtracting Price over to the other side. Now it's a rootfinding problem. If you only have one variable you're solving for (looks to be the case), then Roots.jl is a good choice.
fzero(f, a::Real, b::Real)
will search for a solution between a and b for example, and the docs have more choices for algorithms when you don't know a range to start with and only give an initial condition for example.
In addition, KINSOL in Sundials.jl is good when you know you're starting close to a multidimensional root. For multidimensional and needing some robustness to the initial condition, I'd recommend using NLsolve.jl.
There's nothing out of the box no. Root finding is a science in itself.
Luckily for you, your function has an analytic first derivative with respect to r. That means that you can use Newton Raphson, which will be extremely stable for your function.
I'm sure you're aware your function behaves badly around r = -1.

HaxeFlixel Puyo Puyo

I've been wanting to make a block type game for a while now but have never understood how to actually make one. I have googled forever and there is not much and what is there comes with a stipulation that I am not wanting to bother with (gpl license, entire code base, AND the license in any project, bleh). So I took to a forums with my problem. I did not know it, but I was trying to make a Puyo Puyo type game. With blocks dropping from the ceiling and then clearing if there's a match of 3 or more. I had no idea on how to do the matching. Which is what I wanted to know. A very nice, charming, and intelligent fellow provided me with this:
http://hastebin.com/ziyejejoxu.js
Granted, that's quite a lot, but the way he managed to code it allowed me to somewhat grasp it. However, there is a single infuriating problem. One, exactly ONE, line of code does not compile and breaks. I asked him if I could email him about it and he said okay. I haven't go a response yet so I may not be getting one so I'm taking this here. Here is how I am using the code so far. There are two parts, the play state, and the puzzle piece:
http://pastebin.com/SvMR9mMb
The program breaks in the playstate, giving this error:
source/PlayState.hx:291: characters 33-52 : Array access is not allowed on x : Int -> Int
What I have tried:
I had assumed that it was not allowed because the puzzle piece x is a float, and of course, you can't push a float into an int array. So what I did was simply in the puzzle piece first, convert the the float to an int. That did not work. THEN in the state, I switched the float to an int. That did not work. As an exercise, I attempted to convert a Flixel game to HaxeFlixel to see if I could learn anything. I probably did it wrong and did not.
So the question is: Why does that line not compile and what do I need to do to make it compile or to achieve it's intended purpose?
The syntax is wrong. push is a function, and function calls use (). [] is for array access (hence the error message).
This should work:
if (this_piece_is_in_a_match) matched_pieces.push(_i);

Hard coding in C++

I have an assignment to submit in this week. And I did not understand this jargon "hardcode". It's my first class in C++ , where my professor asked me to demonstrate a simple math operation. By using all the 9 integral data types and a single "hard coded" value. Can some one please explain what hardcoding is? I am new to c++ and would appreciate if some one can throw some light on this.
Thanks!
Basically it means that the value is set inside the source code. If you asked for the variable it's not hardcoded, but if you say int x = 5; then x has been hardcoded to 5.

Functional alternative to caching known "answers"

I think the best way to form this question is with an example...so, the actual reason I decided to ask about this is because of because of Problem 55 on Project Euler. In the problem, it asks to find the number of Lychrel numbers below 10,000. In an imperative language, I would get the list of numbers leading up to the final palindrome, and push those numbers to a list outside of my function. I would then check each incoming number to see if it was a part of that list, and if so, simply stop the test and conclude that the number is NOT a Lychrel number. I would do the same thing with non-lychrel numbers and their preceding numbers.
I've done this before and it has worked out nicely. However, it seems like a big hassle to actually implement this in Haskell without adding a bunch of extra arguments to my functions to hold the predecessors, and an absolute parent function to hold all of the numbers that I need to store.
I'm just wondering if there is some kind of tool that I'm missing here, or if there are any standards as a way to do this? I've read that Haskell kind of "naturally caches" (for example, if I wanted to define odd numbers as odds = filter odd [1..], I could refer to that whenever I wanted to, but it seems to get complicated when I need to dynamically add elements to a list.
Any suggestions on how to tackle this?
Thanks.
PS: I'm not asking for an answer to the Project Euler problem, I just want to get to know Haskell a bit better!
I believe you're looking for memoizing. There are a number of ways to do this. One fairly simple way is with the MemoTrie package. Alternatively if you know your input domain is a bounded set of numbers (e.g. [0,10000)) you can create an Array where the values are the results of your computation, and then you can just index into the array with your input. The Array approach won't work for you though because, even though your input numbers are below 10,000, subsequent iterations can trivially grow larger than 10,000.
That said, when I solved Problem 55 in Haskell, I didn't bother doing any memoization whatsoever. It turned out to just be fast enough to run (up to) 50 iterations on all input numbers. In fact, running that right now takes 0.2s to complete on my machine.

Resources