Login Page - Create Account

Support Board


Date/Time: Thu, 02 May 2024 17:23:57 +0000



Post From: [ACSIL] float conversions

[2013-12-30 19:11:05]
mainframer - Posts: 9
The key to my solution involves creating my own add and multiply functions for these floats. I provide below the necessary functions for this solution. For the sake of time, I have left out petty details like function parameters, so you will have to figure the rest out yourself. Ask questions if you are confused.

addFloat() The add function simply increments the price float by the sc.TickSize, then rounds that sum with sc.RoundToTickSize.

multiplyFloat() Multiplies a float by calling addFloat() 'x' number of times.

numberOfPrices() Calculates the number of prices in a range of prices 'x' and 'y'. To do this, you must convert x and y to int form and return x - y. The key is to convert x and y into integers while preserving their significant figures.
// Let's say x and y are at sc.TickSize == 0.01
int intX = (int) multiplyFloat(x, 100);
int intY = (int) multiplyFloat(y,100);
return intX - intY

buildPriceList() Determines the size of the set of prices between a provided range. First define an array of prices, then, for every element in that array, increment the price starting from the lowest in the range.
// Define array of prices.
int size = numberOfPrices();
float prices[size];

// Determine each price by incrementing with the tick price.
float currentPrice = 0; // You can start with another price.
for(int i=0; i < size; i++){
prices[i] = addFloat(currentPrice, sc.TickSize);
}

return prices;