100 MyLong from Double should return 199.79 = 0
110 MyLong from Double should return 199.79 = 100
120 MyLong from Double should return 199.792 = 199
200 MyLong from Single should return 199.79 = 204472
201 MyLong from Single should return 199.79 = 204472
210 MyLong from Single should return 199.79 = 100
220 MyLong from Single should return 199.792 = 199
MySingle = (-11.5) + (-11.5)
MyInteger = MySingle
Hserprint MyINteger
'This returns -23 at the terminal ( correct)
HSerprintCRLF
MySingle = (-11.0) + (-11.5)
MyInteger = MySingle
Hserprint MyINteger
'This returns -11 at the terminal (incorrect)
Simple float maths using Single or Double is failing. Accepting the Help works but the attached code fails. The two example above return
My notes say rotate for "advance variables", therefore, I assumed all four advanced types.
The compiler seems to only support longInt and UlongInt. See code segment from compiler.
....'Check var typeIfNotIsIntType(VarType)Then'ErrorTemp=Message("BadCommandType")ReplaceTemp,"%command%","Rotate"ReplaceTemp,"%type%",VarTypeLogErrorTemp,OriginGotoCompileNextRotateEndIf....FunctionIsIntType(InTypeAsString)AsInteger'Returns true (-1) if input type is an integer variableDimThisTypeAsStringThisType=LCase(InType)SelectCaseThisTypeCase"const","byte","word","integer","long","ulongint","longint":Return-1CaseElse:Return0EndSelectEndFunction
What is correct ? Just the integer types of longInt and UlongIt and/or floats and the compliler needs updating.
Help now shows only integer types of longInt and UlongIt until this is resolved.
Last edit: Anobium 2021-07-19
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
There is some weird maths happening. 0-3.142 = 6.nnnn, 0-10=20.mmm ???
Yet other numbers work 0-1, 0-4 etc. I cannot determine a sequence - most be broken in the asm
Bug. Basic maths are incorrect.
Evan
Example code.
HSerPrintCRLF2HSerPrint"Maths test "HSerPrintCRLF2DimccountassingleDimcalcresultasdoubleDimresultasIntegerHSerPrintCRLFHSerPrint"Use floats with negate"HSerPrintCRLF'Assign a value to a double variableccount=3.142'Convert Double to Long to get the resultresult=ccountHSerPrintleft(strInteger(result)+" ",8)HSerPrintCRLF2'simple maths ....calcresult=0-ccount'Convert Double to Long to get the resultresult=calcresultHSerPrintleft(strInteger(result)+" ",8)HSerPrintCRLF2
Last edit: Anobium 2021-07-20
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If doing math with floats you need to use either the single or double variable type.
The float data type has only 6-7 [ needs confirmation by Hugh]decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point.
Floating point numbers are not exact [ Hugh.. is this true ?] , and may yield strange results when compared using conditions (IF etc). For example 6.0 / 3.0 may not equal 2.0. Users should instead check that the absolute value of the difference between the numbers is less than some small number.
As floating point numbers are not exact we need the following functions:
INT() ..
ROUND()
Conversion from floating point to integer math results in truncation. This is ready functional.
dimmySingleVarasSinglemySingleVar=2.9'A float type variabledimmyLongVarasLongmyLongVar=mySingleVar' will set myLongVar to 2
but, we will need to ensure users do not mess up. Should we add INT ( Single or Double ) ?
myLongVar = INT( mySingleVar )
And, users may want round off during the conversion process, users need to add 0.5: As follows:
Analysis - the trailing zero in the string constants messes up the compiler. Removing the trailing zeros generates ASM that looks ok. Could be the '.00' after the '10' but anyway this is not being processed correctly.
I think this works. I don't know if this helps you or not. This returns component parts of a single precision number.
SubExtractSngParts(sngasSingle,sgnasByte,expasByte,mantissaasLong)dimtmplongasLongMoveSngToLongsng,tmplongmantissa=tmplong&0x7FFFFFtmplong=FnLSR(tmplong,23)exp=tmplong&0xFFtmplong=FNLSR(tmplong,8)sgn=tmplongEndSubSubMoveSngToLong(sngn1asSingle,snum1asLong)'Moves 4 byte single precision to 4 byte Long' I haven'tfoundanyotherwaytodothissnum1.0=sngn1.0:snum1.1=sngn1.1:snum1.2=sngn1.2:snum1.3=sngn1.3snum1.4=sngn1.4:snum1.5=sngn1.5:snum1.6=sngn1.6:snum1.7=sngn1.7snum1.8=sngn1.8:snum1.9=sngn1.9:snum1.10=sngn1.10:snum1.11=sngn1.11snum1.12=sngn1.12:snum1.13=sngn1.13:snum1.14=sngn1.14:snum1.15=sngn1.15snum1.16=sngn1.16:snum1.17=sngn1.17:snum1.18=sngn1.18:snum1.19=sngn1.19snum1.20=sngn1.20:snum1.21=sngn1.21:snum1.22=sngn1.22:snum1.23=sngn1.23snum1.24=sngn1.24:snum1.25=sngn1.25:snum1.26=sngn1.26:snum1.27=sngn1.27snum1.28=sngn1.28:snum1.29=sngn1.29:snum1.30=sngn1.30:snum1.31=sngn1.31EndSub
Later,
Clint
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I finally got out of bed, it's 7am here. I'll try and do that this morning sometime. I think I read Single Precision addition and subtraction work, but I went ahead and made my own functions just to get a better understanding of the algorithms. I couldn't get "&" to work on a Single number, that's why I had to transfer it to a Long like I did.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
@Clint. Thank you for your great analysis. I know you have spent many,any hours on this key baseline work. We should have done this work up front, but, we did not.
I have asked Hugh to review the whole thread as we have a good analysis of the floats implementation. I emailed Hugh just now.
Again, thank you.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is another file to try. Everything should work. I added a HSerPrintSng sub to print single precision numbers out. It is limited to what can fit into a long variable. Precision is lost due to Single precision inaccuracies, but isn't too bad.
This thread is a place holder for the final development and testing of the float capability for GCBASIC.
News 04.04.2024 - Build 1381
We have made great progress with the floats implementation
Progress
See here https://sourceforge.net/p/gcbasic/discussion/579125/thread/e777a80dfa/?limit=25#9b84.
Download
The Floats capability is now general release via GCSTUDIO download. Linux build will follow in late April 24.
Last edit: Anobium 2024-04-04
Help
Please see https://github.com/Anobium/Great-Cow-BASIC-Help/blob/master/source/variablesadvanced.adoc
Respond to this post when you have questions regarding the Help or the documented capabilities.
Last edit: Anobium 2021-07-18
Issues
Please respond this post with new ( or updating ) issues. Please post the issue and the source code.
Last edit: Anobium 2021-07-18
Basic maths is failing ( from Bill Roth).
Tests are like shown below - all tests should return 199.
Great Cow BASIC
Print FLOAT TEST
18F27Q43
100 MyLong from Double should return 199.79 = 0
110 MyLong from Double should return 199.79 = 100
120 MyLong from Double should return 199.792 = 199
200 MyLong from Single should return 199.79 = 204472
201 MyLong from Single should return 199.79 = 204472
210 MyLong from Single should return 199.79 = 100
220 MyLong from Single should return 199.792 = 199
MySingle = (-11.5) + (-11.5)
MyInteger = MySingle
Hserprint MyINteger
'This returns -23 at the terminal ( correct)
HSerprintCRLF
MySingle = (-11.0) + (-11.5)
MyInteger = MySingle
Hserprint MyINteger
'This returns -11 at the terminal (incorrect)
Simple float maths using Single or Double is failing. Accepting the Help works but the attached code fails. The two example above return
pp Bill
Last edit: Anobium 2021-08-14
Basic maths using subtraction is falling.
Similar result to addition errors only 3 digit decimals is correct with only two of the tests working as expected.
Posted by Evan
Rotate scope of operations.
My notes say rotate for "advance variables", therefore, I assumed all four advanced types.
The compiler seems to only support longInt and UlongInt. See code segment from compiler.
What is correct ? Just the integer types of longInt and UlongIt and/or floats and the compliler needs updating.
Help now shows only integer types of longInt and UlongIt until this is resolved.
Last edit: Anobium 2021-07-19
Negate scope of operations.
My notes say Negate for "advance variables", therefore, I assumed all four advanced types.
The compiler support is not working.
What is correct ? Just the integer types of longInt and UlongIt and/or floats and the complier needs updating.
Help currenly shows all four advanced types are supported.
What is the correct ? just longInt and UlongInt ?
Subtraction issue.
There is some weird maths happening. 0-3.142 = 6.nnnn, 0-10=20.mmm ???
Yet other numbers work 0-1, 0-4 etc. I cannot determine a sequence - most be broken in the asm
Bug. Basic maths are incorrect.
Evan
Example code.
Last edit: Anobium 2021-07-20
Issue - What are the essential functions ?
If doing math with floats you need to use either the single or double variable type.
The float data type has only 6-7 [ needs confirmation by Hugh] decimal digits of precision. That means the total number of digits, not the number to the right of the decimal point.
Floating point numbers are not exact [ Hugh.. is this true ?] , and may yield strange results when compared using conditions (IF etc). For example 6.0 / 3.0 may not equal 2.0. Users should instead check that the absolute value of the difference between the numbers is less than some small number.
As floating point numbers are not exact we need the following functions:
Conversion from floating point to integer math results in truncation. This is ready functional.
but, we will need to ensure users do not mess up. Should we add INT ( Single or Double ) ?
And, users may want round off during the conversion process, users need to add 0.5: As follows:
but, we will need to ensure users do not mess up. Should we add ROUND( Single or Double ) ?
mySingleVar = 2.9
myLongVar = ROUND(mySingleVar) '3
Or, we can decide not to included INT() & ROUND() leaving the users to use the intger assignment and add 0.5 for INT() and ROUND() respectively.
Your thoughts?
Last edit: Anobium 2021-07-19
longInt and UlongInt do not accept full range. It is assummed that all advanced variables have the same constraint... will not accept full range.
Compiler will not accept the complete (full range) of values when using an assignment from a constant string.
We need to test the extremes on all four advanced variables.
Last edit: Anobium 2021-07-21
Solutions that work !! :-)
Please respond to this post with programs that work!
Last edit: Anobium 2021-07-18
Working pseudo multiplication.
only works with specific source numeric values!!
This shows pseudo multiplication using repeat-end repeat but using floats is slow.
This code is shown in the help.
Last edit: Anobium 2021-07-19
Whats up? Do we have floats? and floating point math? if so, hooray!
@mmotte - Yes. early days but we have stability in the compiler to review and test floats.
Look at the posts and the Help to see state of play but please do try to use.
Early days.
Issue - Micro controller stops execution under certain conditions.
Last edit: Anobium 2021-07-20
Analysis - the trailing zero in the string constants messes up the compiler. Removing the trailing zeros generates ASM that looks ok. Could be the '.00' after the '10' but anyway this is not being processed correctly.
@williamroth
Bug - string constants used to assign values to a double that have trailing zeros does not generate valid asm.
Last edit: Anobium 2021-07-20
I think this works. I don't know if this helps you or not. This returns component parts of a single precision number.
Later,
Clint
@ckoehn Can you post an example piece of code to help me understand usage? Cheers
I finally got out of bed, it's 7am here. I'll try and do that this morning sometime. I think I read Single Precision addition and subtraction work, but I went ahead and made my own functions just to get a better understanding of the algorithms. I couldn't get "&" to work on a Single number, that's why I had to transfer it to a Long like I did.
Here is what I've been doing the last few days....
I can't seem to add attachments so....
Later,
Clint
@Clint. Thank you for your great analysis. I know you have spent many,any hours on this key baseline work. We should have done this work up front, but, we did not.
I have asked Hugh to review the whole thread as we have a good analysis of the floats implementation. I emailed Hugh just now.
Again, thank you.
Here is another file to try. Everything should work. I added a HSerPrintSng sub to print single precision numbers out. It is limited to what can fit into a long variable. Precision is lost due to Single precision inaccuracies, but isn't too bad.
Later,
Clint
The calc 1356.249088 * 236.249984 = 320339.968 should be 320413.8253400146. So, an error of 73.857340014592.
Should we be concerned?
Depends if the error is in your favor or the Bank's :)
LOL....