|
Forum Index : Microcontroller and PC projects : CMM2 - scientific format
| Page 1 of 2 |
|||||
| Author | Message | ||||
| Nimue Guru Joined: 06/08/2020 Location: United KingdomPosts: 425 |
One of my sanity inducing mindfull-ness type things I do is look for number sequences. (See https://oeis.org/ if you want maximum geek). Currently hunting for numbers of the form: ![]() ... which are also square numbers. Where the formula represents a k-agon based pyramid (stacking cannon balls problem). The following code works fine: Function sum(x) k=8 'an octagonal based pyramid sum = ((0.5*k-1)*x^2)-((-0.5*k+2)*x) End Function Function is_square$(i) If Sqr(i) = Int(Sqr(i)) Then is_square$="true" Else is_square$="false" End If End Function Sub square() For x = 1 To 10000000 If is_square$(sum(x)) = "true" Then Print x Print #1, x End If Next x End Sub square() but once the numbers get large, they are scaled to scientific notation. Thus... 2 32 450 6272 87362 1.2168e+06 This confuses my students, most of which have not seen this notation before. I naively thought that if I saved the output to file, that this would expand the number. Nope. I know I can add format$(x,"%.20g") to force these larger numbers into expanded form -- but that looks even more like weird code to my students. Q: Is there any way to either scientific notation and just display the full number? OPTION SCIBASE OFF for example? Or is there some other CMM2/MMBasic-fu that can make scientific notation disappear? Would even be happy if this was just enabled when output is directed to a file? As a second supplementary Q: Every number is more than an order of magnitude bigger than the previous - this means that beyond the sixth term the rate of discovery grinds to a halt. In Python (dont hate me) I have a library that I can load that displays a "spinner" and/or progress bar to show that the code hasn't hung / died. Whilst I can simulate this in the CMM2, the act of "Printing" itself slows the code down. Other than printing a "..." every 1000 iterations or so, any clever ways to show that code is still running? Cheers Nim Edited 2021-02-22 23:54 by Nimue Entropy is not what it used to be |
||||
| matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 10591 |
print str$(x,15,0) |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
with limitations, if you convert the number to integer you get the significant digits: > dim a% > a%=1.2168e+06 > ? a% 1216800 > a%=2^63 > ?a% -9223372036854775808 etc... does that help? Edited 2021-02-22 23:57 by CaptainBoing |
||||
| Nimue Guru Joined: 06/08/2020 Location: United KingdomPosts: 425 |
Perfect -- that is "easier" for them to understand -- does what it says on the tin. Thank you. N Edited 2021-02-22 23:59 by Nimue Entropy is not what it used to be |
||||
| Nimue Guru Joined: 06/08/2020 Location: United KingdomPosts: 425 |
Nice - yes it does --- Is "integer" math quicker too? As in: For x% = 1 to 100000 next x% or is the % ignored in the above? Nim Edited 2021-02-23 00:04 by Nimue Entropy is not what it used to be |
||||
| NPHighview Senior Member Joined: 02/09/2020 Location: United StatesPosts: 213 |
...and don't hesitate to teach them scientific (and engineering) notation. They'll use it forever more. - Steve Live in the Future. It's Just Starting Now! |
||||
| Nimue Guru Joined: 06/08/2020 Location: United KingdomPosts: 425 |
Agree -- but most are only 10-12 years old. Standard form appears in GCSE (for a couple of marks). They struggle with significant figures as it is ;-) edit >>> Odd things happening when i use "quote" function in the forum... adding a URL link?? N Edited 2021-02-23 02:38 by Nimue Entropy is not what it used to be |
||||
| CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2171 |
On the bog standard MM (which I use in reasonable amounts) Integer maths is very much faster than floats, but I don't know how much so on those beasts with hardware FPUs. I suspect there is still a healthy gap... perhaps some tests... timer=0 for n%=1 to 1000000:next ?timer timer=0 For m!=1 to 1000000:next ?timer and following on from NP's tip above, engineering notation is a very good thing to teach. check these out EDIT: just did the tests myself, given that its on a 48MHz PIC32, there isn't much in it between ints and floats... pleasantly surprised: Int 23892 Float 26683 just three seconds in it, over 1M iterations... I have new found respect for floats on the humble MM. So not "very much" really - a bit faster p.s. yes, just recently I have noticed rogue URL tags being inserted in quoted posts too Edited 2021-02-24 03:38 by CaptainBoing |
||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3477 |
I emailed Glenn about this several days ago. He replied and I sent him some examples, so he's aware of it (said he had fixed something else which might have broken it). PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
| JohnS Guru Joined: 18/11/2011 Location: United KingdomPosts: 4147 |
Oh, Glenn may be getting too many reports - I also emailed. John |
||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3477 |
Cap'n's code for F4: 4667 6816 for CMM2: 688.069 722.549 PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
| zeitfest Guru Joined: 31/07/2019 Location: AustraliaPosts: 622 |
now try timer=0 for n%=1 to 1000000:next i% = i% + 1 ?timer timer=0 For m!=1 to 1000000:next x! = x! + 1.0 ?timer Edited 2021-02-24 09:31 by zeitfest |
||||
| TimD Newbie Joined: 23/02/2021 Location: United KingdomPosts: 31 |
Not sure how clever it is, but an efficient method may be to use SETTICK to call a subroutine at regular intervals; the subroutine can then display your current value of x. Best regards, Tim. |
||||
| Plasmamac Guru Joined: 31/01/2019 Location: GermanyPosts: 596 |
maybe use the VBI ? mode x,x,x,int Plasma |
||||
| Nimue Guru Joined: 06/08/2020 Location: United KingdomPosts: 425 |
Nice - investigating now N Entropy is not what it used to be |
||||
| Nimue Guru Joined: 06/08/2020 Location: United KingdomPosts: 425 |
OOhh - that's interesting. Both replies use interrupts -- off to play. N Entropy is not what it used to be |
||||
| zeitfest Guru Joined: 31/07/2019 Location: AustraliaPosts: 622 |
What times show on these ? Anyone ? |
||||
| Nimue Guru Joined: 06/08/2020 Location: United KingdomPosts: 425 |
CMM2: 3568.879 4387.374 N Entropy is not what it used to be |
||||
| lizby Guru Joined: 17/05/2016 Location: United StatesPosts: 3477 |
timer=0 for n%=1 to 1000000:next i% = i% + 1 ?timer timer=0 For m!=1 to 1000000:next x! = x! + 1.0 ?timer What times show on these ? Anyone ? CMM2: 3568.879 4387.374 N Something wrong there. With the whole series copied into the prompt, and a dummy command after the final ?timer, I get this: > timer=0 > for n%=1 to 1000000:next > ?timer 658.13 > > timer=0 > For m!=1 to 1000000:next > ?timer 695.027 > > timer=0 > for n%=1 to 1000000:next > i% = i% + 1 > ?timer 678.432 > > timer=0 > For m!=1 to 1000000:next > x! = x! + 1.0 > ?timer 711.618 With this timer=0 for n%=1 to 1000000:next ?timer timer=0 For m!=1 to 1000000:next ?timer timer=0 for n%=1 to 1000000:next i% = i% + 1 ?timer timer=0 For m!=1 to 1000000:next x! = x! + 1.0 ?timer x! = x! + 1.0 About 20ms added for "i% = i% + 1" and 16ms for "x! = x! + 1.0". PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
| Nimue Guru Joined: 06/08/2020 Location: United KingdomPosts: 425 |
The "issue" with mine was: your code.... timer=0 for n%=1 to 1000000:next i% = i% + 1 ?timer Inadvertently I figured the i%=i%+1 needed to be inside the for loop. my code: timer=0 for n%=1 to 1000000 i% = i% + 1 next ?timer Entropy is not what it used to be |
||||
| Page 1 of 2 |
|||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |