It does make a difference for the program: the formula [latex]R(i,b) = 10^{\frac{i}{b}}[/latex] generates incorrect values.
DEFINT A-Z ' Set default variable type to integer.
DIM SHARED values(1 TO 216)' An array for the E24 values and E192 values.
DIM SHARED lgb10 AS DOUBLE ' Define log10 so we don't have to recalculate it.
lgb10 = LOG(10)
CLS
FOR n = 1 TO 24 ' Calculate the E24 values.
values(n) = 10 ^ (1 + n / 24)
IF n >= 10 AND n <= 16 THEN values(n) = values(n) + 1 'Fiddle to fit E24
values(n) = values(n) * 10
NEXT
values(22) = 820' Fiddle to fit E24
FOR n = 1 TO 192
values(n + 24) = 10 ^ (2 + n / 192)
NEXT
values(209) = 920' Fiddle to fit E192
FOR n = 1 TO 24
PRINT values(n)
NEXT
INPUT "Enter value"; value#
lgval# = LOG(value#) / lgb10' Take log10 of the value.
ex = INT(lgval#)' Exponent is the integer part of log 10 of the value.
dec#= lgval# - ex' store the decimal part of log10.
el = dec#* 24' Work out the nearest preferred number.
mnt = 10 ^ (2 + dec#)' get the mantissa.
ex = ex - 2' Preferred numbers in the array are multiplied by 100 so /100.
IF el = 0 THEN ' If zero, wrap round to highest value and /10 to compensate.
ex = ex - 1
el = 24
mnt = mnt * 10
END IF
' A fiddle to align the result to the preferred number.
dif = values(el) - mnt' The difference between the ideal and preferred value.
IF el > 1 THEN IF dif > mnt - values(el - 1) THEN el = el - 1
IF el < 24 THEN IF dif < mnt - values(el + 1) THEN el = el + 1
PRINT "Index"; el
PRINT "Mantissa"; mnt
PRINT "Exponent:"; ex
PRINT "Nearest E24 Value"; values(el) * 10 ^ ex
DIM lg10 AS DOUBLE
DEFINT A-Z
lg10 = LOG(10)
INPUT "Enter value"; r#
lg10r# = LOG(r#) / lg10
ex = INT(lg10r#)
PRINT ex
E96 = CINT(10 ^ (2 + CINT(96 * LOG(10 ^ (lg10r# - ex)) / lg10) / 96)) * 10 ^ (ex - 2)
PRINT E96
I am using look up tables. The formula creates all the values and the above transposition of the formula indexes the tables. I could have used a search to find the value but that would probably have proven slow on the E192 values.
Why create the tables on the fly? Are you that short on eeprom or data flash space?
With QBasic you might put entire look-up tables in data lines to read on request.
Still faster than Turbo-Pascal.
Will Qbasic programs even run on windows?
So you think interpreted QBasic is faster that compiled Turbo Pascal
Sorry Sir, I don't think it. I know it.
We made a speed test simply using a stop watch for the same math problem to be executed using Turbo Pascal and QBasic.
There were some complicated formulas involved to calculate a certain retirement payment for a certain time and how many years someone would have to save a certain amount of money in monthly deposits to have the money "consumed" after the time period calculated for.
QBasic was the winner - almost double speed.
Boncuk, what does that have to do with a table lookup?
Boncuk you're not serious are you? Use a basic stamp interpreted from eeprom (pic based) and the SAME pic with the SAME effective program in flash. The PIC will beat the stamp 4 to one or better, probably much more.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?