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"
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'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 needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I working on a Swift program and now I have a problem:
How do you compare a Int64 with a Int64?
if(msgCount.value != msg.longLongValue){
Error:
Binary operator '!=' cannot be applied to operands of type 'Int64' and 'Int64'
You can directly compare for equality
Try this, it will help you:
let msgCount : Int64=100
let msg : Int64=101
if(msgCount != msg ){
// perform your logic here.
}
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 8 years ago.
Improve this question
Hi this is my first lua code but I get a error pls fix it thx in advanced if you do get this working. I have a feeling its a small thing I'm missing.
class 'Autochat'
TalkTimer = Timer()
local TalkDelay = 1 -- in minutes
local active = 1
function
if active = 0 then
return
end
if active ~= "0" then
if(TalkTimer:GetSeconds() > (60 * timeDelay)) then
Chat:Broadcast("Hi the admin is offline.", Colors(0, 255, 0))
TalkTimer:Restart()
end
end
end
Autochat = Autochat()
The function is missing a name. Lua reads to the next line looking for the function's name and gets confused when it finds an if statement.
Also, the first if statement should be if active == 0 then because == is the comparison operator.
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);
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've been using the simple_statistics gem, but im looking to calculate the EMA on the last x records. For example (when calculating WMA)
#stockticker.ema10 = s.stocktickers.last(10).map(&:current_price).map{|f| f.to_f}.wma
I was wondering if anyone can provide advise on how I got about calculating the EMA in rails?
It looks like the Moving Averages gem might be what you're looking for. Here is a copy of their exponential_moving_average method for reference as well.
class Array
def exponential_moving_average(idx=nil, tail=nil)
idx, tail = idx_and_tail_or_defaults(idx, tail)
valid_for_ma(idx, tail)
alpha = 2.0 / (tail + 1)
n = (1..tail).to_a.map{|tidx| (1 - alpha) ** (tidx - 1) * self[idx - tidx + 1]}.sum
d = (1..tail).to_a.map{|tidx| (1 - alpha) ** (tidx - 1)}.sum
n / d
end
alias_method :ema, :exponential_moving_average
end
I am the developer of Statsample-timeseries gem which is an extension of Statsample, an advance statistical suite in Ruby. It has quite many statistical methods (including EMA) which you can perform on your data.
If you need any assistance, I will be very happy to help out. :)