Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I thought lroundf would round my float to the next highest number at .5 steps. E.g. 1.5f would be rounded to 2.0f.
I tried, but my code tells me otherwise:
int roundUp = 1.5f;
NSLog(#"no round up: %d", roundUp);
NSLog(#"lroundf: %ld", lroundf(roundUp));
And my output is:
no round up: 1
lroundf: 1
How do I correctly round up my float?
int rounded = lroundf(theFloat); NSLog(#"%d",rounded);
int roundedUp = ceil(theFloat); NSLog(#"%d",roundedUp);
int roundedDown = floor(theFloat); NSLog(#"%d",roundedDown);
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I am trying to write macro to pick up slices which I would like to include in my MIP. So far it looks like this:
LowerStack = getNumber("prompt", 10);
UpperStack = getNumber("prompt", 10);
run("Z Project...", "start=" + LowerStack) ("stop=" + UpperStack) ("projection=[Max Intensity]");
It recognizes the Lower slice which I want to pick up, but not the upper one.
Any suggestions on what do I do wrong?
The syntax of the third line is incorrect. This works:
LowerStack = getNumber("Lower", 10);
UpperStack = getNumber("Upper", 10);
run("Z Project...", "start=" + LowerStack + " stop=" + UpperStack + " projection=[Max Intensity]");
Note that I also changed the string in the two prompts because you would likely get an error by them not being unique.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I'm practicing F# for the first time and I thought I'd try to make a program that would calculate the areas of different kinds of shapes. However, the portion that finds the area of a circle is giving me a lot of trouble.enter code here
elif stringInput = "2" then
let PI = 3.14156
printfn "What is the circle's radius: "
let radiusString = System.Console.ReadLine()
let radiusInt = radiusString |> float
let cirlceArea = (radiusInt * radiusInt) * PI
printfn "The area of the circle is : %d" cirlceArea
I'm sure it has something to do with the radiusString |> float part of the code, but nothing I've tried works and I've had no luck in finding any examples that can help. What can I do?
Ok I just found out the problem was that I was using %d instead of %f
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to say if the desired location in the field is 1 return true otherwise return false. Why is this code not working?
fireShot :: Coordinate -> Field -> Bool
fireShot coord Shipfield
| nth ( fst(coord)((nth snd(coord)) ShipField) == 1 = True
| otherwise = False
The brackets in the guard are not balanced, you open five brackets, and you close four brackets. Furthermore variables start with a lowercase, so it should (probably) be shipfield, not Shipfield.
I think it might be better to use pattern matching to obtain the first and second coordinate, since this will make the code more clean. You furthermore do not need guards to return True and False. You can replace the function with:
fireShot :: Coordinate -> Field -> Bool
fireShot (x,y) shipfield = nth x (nth y shipfield) == 1
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I am getting a lot of reports that a function that is called by applicationWillTerminate, not exclusively by that but I have a feeling that the root of the issue might have something to do with that. I am getting these reports from Fabric.io Crashlytics. Anyways the reported line causing the crash is the following:
return Int(NSDate().timeIntervalSince1970 * 1000)
This code has also been working in most cases but has risen up the list of crashes. Can anyone give me any hint as to why this might be crashing.
My guess is that your crashes are coming from 32-bit devices, where Int(NSDate().timeIntervalSince1970 * 1000) is impossible because NSDate().timeIntervalSince1970 * 1000 is bigger than Int.max.
Here's a little playground code to show that that is true:
let i = Int32.max // max size of Int on 32-bit
i // 2147483647
let j = NSDate().timeIntervalSince1970 * 1000
j // 1486250171084.633
And we can proceed to test it like this:
// let's try to simulate the crash
Int32(j)
// yup, crash:
// "Double value cannot be converted to Int32 because the result would be greater than Int32.max"
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to add a few strings to an array. the strings have a variable part like "test1" , "test2" , "test3" and so on. I thought using a for loop would be a good idea but i get some errors.
here is the code:
for (int i=0; i<19; i++) {
[detailImageArray addObject:#"army%#.jpg",i];
}
You can use +[NSString stringWithFormat:] method as follows:
for (int i = 0; i < 19; i++) {
[detailImageArray addObject:[NSString stringWithFormat:#"army%d.jpg",i];
}