// COMMON ENTRY POINT FOR SCRIPT, MICROSERVICE, TEST, COMPOSITION, ETC
let main arg1 arg2 arg3 =
let srcNumberToTranslate=arg1
let srcNumberBase:NumberBase= parseCLIOptionsForNumberBase arg2
let targetNumberBase = parseCLIOptionsForNumberBase arg3
// OUTER ONION TEST/PRINT
dumpIt $"OUTER ONION\n Number to translate: {srcNumberToTranslate} Number Base {srcNumberBase} Base to translate to base: {targetNumberBase}"
// BUSINESS CONSISTENCY - IS DATA IN FORMAT THAT MAKES SENSE TO PROBLEM
// USE TRIES TO HANDLE ANY ERRORS AS THE BIZ DESIRES - ERRORS ARE BIZ ISSUES, NOT CODING ONES
// IN A LARGE MICROSERVICES ENVIRONMENT, HERE IS WHERE YOU MIGHT FORK OR JOIN DATA STREAMS IN THE OUTER OS
// ONCE WE'RE DONE HERE, SHOULD HAVE INCOMING NUMBER IN A BIG N-LENGTH STRING IN BASE 10
let mainNumber = try (spFoilitByScientificNotation srcNumberToTranslate)[0] with |_ -> "0"
let exponentNumber = try (splitByScientificNotation srcNumberToTranslate)[1] with |_ -> "0"
let exponentSign = if srcNumberToTranslate.Contains("-") then "-" else "+"
let numberWithDecimal=makeSureStringHasDecimalOrAddAtEnd mainNumber
// BUSINESS CONSISTENCY TESTS
dumpIt $"BIZ CONSISTENCY\n IsScientificNotaion {(isScientificNotation srcNumberToTranslate)} Main Number {mainNumber} Exponent Number {exponentNumber} Exponent Sign{exponentSign} NumberWithDecimal {numberWithDecimal}"
let superHugeNumberString = moveDecimal (makeSureStringHasDecimalOrAddAtEnd mainNumber) exponentSign exponentNumber
let exponentWalkingDirection = if superHugeNumberString.[0]='.' then -1 else 1
let inputBase =
match srcNumberBase with
|BaseInBaseTenNotation(x) -> BigInteger(x)
|FunkyOddballBase(x) -> BigInteger(10) // NOT IMPLEMENTED
let temporarySums =
superHugeNumberString |> Seq.mapi(fun i x->
let exponentMultiplier:bigint =
if exponentWalkingDirection = 1
then bigint ( superHugeNumberString.Length-1 - i * exponentWalkingDirection)
else bigint ((i+1)*(-1))
let digitValueMultiplier:bigint = BigInteger.Pow(inputBase,(int)exponentMultiplier)
//let digitValue = BigInteger.Parse(string x)
let digitValue=convertDigitToValue x targetNumberBase |> bigint
let runningResult = digitValueMultiplier * digitValue
runningResult
)
// ODDBALL BASES NOT CODED
dumpIt $"Running result {temporarySums}"
let convertedToBaseTen:bigint = temporarySums |> Seq.sum
dumpIt $"converted to base ten bigint {convertedToBaseTen}"
let rur=
match targetNumberBase
with
| BaseInBaseTenNotation x->convertFromBigIntegerToBaseX convertedToBaseTen x
|_->"FUNKY BASE TYPES NOT IMPLEMENTED"
rur