Writing a sorting algorithm based off of Reddit’s here: http://amix.dk/blog/post/19588
I’m having a little trouble getting it all to fit together because some of the System.Math signatures differ in their application.
public class Calculation
{
protected DateTime Epoch = new DateTime(1970,1,1);
protected int EpochSeconds(DateTime date)
{
var td = date - Epoch;
return td.Days*86400 + td.Seconds + ((td.Milliseconds)/1000000);
}
protected int Score(int upVotes,int downVotes)
{
return upVotes - downVotes;
}
public int HotScore(int upVotes,int downVotes,DateTime date)
{
var s = Score(upVotes, downVotes);
var order = Math.Log(Math.Max(Math.Abs(s), 1), 10);
var sign = Math.Sign(s); //Edit from Jonathon Reinhart
var seconds = EpochSeconds(date) - 1134028003;
return Math.Round(order + sign + *seconds/45000, 7);
}
}
Edits for more information
Specifically I’m getting an error on the last line
return Math.Round(order + sign + *seconds/45000, 7);
//error "The * or -> operator must be applied to a pointer"
“
The closest match I can find in the method signature is this:
http://msdn.microsoft.com/en-us/library/f5898377
One recommendation I would make is to use
Math.Sign(Int32). So:Becomes:
Ok, so you’re having problems with this line:
Well for one, you’re probably losing the fractional part in
seconds/45000, because they are bothint. Cast one to double first:((double)seconds / 45000).For two, you’ve likely got a syntactical error
sign + *seconds. Do you mean+or*? It thinks you’re usingsecondslike a pointer.Finally,
Math.Roundreturns adouble, but yourHotScoremethod is returning anint. I’m guessing you want that to return adouble.My guess is that this is what you want:
Also, I don’t think your
EpochSeconds()is correct. I adapted this from here: