Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
18 June, 2013, 07:12:49 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1] 2   Go Down
  Print  
Author Topic: [Axiom] Floating Point Math (and other stuff) -  (Read 2198 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
jacobly
LV5 Advanced (Next: 300)
*****
Offline Offline

Last Login: Today at 02:52:09
Date Registered: 09 October, 2011, 01:53:09
Posts: 200

Topic starter
Total Post Ratings: +150

View Profile
« on: 26 October, 2011, 01:18:09 »
+10

This axiom allows you to access the os variables and do floating point math with them!
Feel free to ask questions instead of trying to read and understand this entire post.

Did you ever want to store the value of the real/complex variable A into the real/complex variable B inside of an axe program? Now it is easier than ever!

1
2
:A→B

1
2
3
4
:#Axiom(CPLXMATH) .varA could be complex
:Select("varA")→Select("varB") .Select( is in the 2nd List Ops menu
:solve() .optional but suggested, frees used memory

But maybe you wanted to store A + B to C.  Well that is almost as simple.

1
2
:A+B→C

1
2
3
4
:#Axiom(CPLXMATH) .varA or varB could be complex
:solve(ᵀ+,Select("varA"),Select("varB"))→Select("varC") .solve( is on the Math Math menu
:solve() .optional, but suggested - frees used memory
In general, solve(ᵀ<op>,<args>) applies <op> to <args>. <op> can be be almost anything from ^, dim( to inString(!
Note: even though Axe changes inString( to inData(, it still does its original function when used in this command. Also, don't close the ( in <op>!

Well that's cool, but can I use Lists you ask? Of course!

1
2
:L₁∗A→L₂

1
2
3
4
:#Axiom(CPLXMATH) .L₁ or L₂ could be complex lists
:solve(ᵀ∗,Select("L₁"),Select("varA"))→Select("L₂")
:solve() .optional but suggested, frees used memory

But I only wanted to used the 42nd number in L₁ you ask? Well, why not!

1
2
:L₁(42)‒A→L₂(42)

1
2
3
4
:#Axiom(CPLXMATH) ... see above
:solve(ᵀ‒,Select("L₁",42),Select("varA"))→Select("L₂",42)
:solve() ... see above
Notice how Select( loads or saves to a variable, and solve( applies an operation to loaded variables.

The above code doesn't work if L₁ is too small, you say? Well why don't we resize L₁.

1
2
:42→dim(L₁)

1
2
3
:#Axiom(CPLXMATH) ...you know
:dim("L₁",42) .notice the slight difference in syntax
Note that solve() is unnecessary because dim does not currently use any memory.

I'll bet you forgot about matricies, you say... Nope!

1
2
3
4
5
6
7
:{5,5}→dim([A])
:For(A,1,5)
:For(B,1,5)
:10A+B→[A](A,B)
:End
:End

1
2
3
4
5
6
7
8
9
10
11
:#Axiom(REALMATH) .only real numbers used AND no arbitrary variable access
:Buff(9)→GDB1 .a temp floating point - they are 9 bytes large
:dim("[A]",5,5)
:For(A,1,5) .remember, A and B are still Axe variables
:For(B,1,5)
:A∗10+B→float{GDB1} .load temp with A∗10+B converted to a floating point
:GDB1→Select("[A]",A,B) .see, I didn't forget matrix support
:solve() .especially important inside loops
:End
:End
Or, if you are familiar with the format of floating point numbers:

1
2
3
4
5
6
7
8
9
10
11
12
:#Axiom(REALMATH) .see above
:"[A]"→Str1
:[008100000000000000]→GDB1 .floating point zero, prepared for 2 digit numbers
:dim(Str1,5,5)
:For(A,1,5)
:For(B,1,5)
:A∗16+B→{GDB1+2} .A and B are between 0 and 10 exclusive, treat as bcd digits
:GDB1→Select(Str1,A,B)
:End
:solve() .delete temp memory at least moderately often (~100 bytes at this point!)
:End

Now for an example that actually does something useful.

1
2
3
:(-B+√(B²‒4AC))/(2A)→C
:(-B‒√(B²‒4AC))/(2A)→D

1
2
3
4
5
6
7
8
9
10
:#Axiom(CPLXMATH) .obviously
:Buff(9)→GDB2 .declare constants
:Buff(9)→GDB4
:2→float{GDB2} .initialize constants
:4→float{GDB4}
:solve(ᵀ/,solve(ᵀ+,solve(ᵀ-,Select("varB")),solve(ᵀ√(,solve(ᵀ‒,solve(ᵀ²,Select("varB")),solve(ᵀ∗,GDB4,solve(ᵀ∗,Select("varA"),Select("varB")))))),solve(ᵀ∗,GDB2,Select("varA")))→Select("varC")
:solve()
:solve(ᵀ/,solve(ᵀ‒,solve(ᵀ-,Select("varB")),solve(ᵀ√(,solve(ᵀ‒,solve(ᵀ²,Select("varB")),solve(ᵀ∗,GDB4,solve(ᵀ∗,Select("varA"),Select("varB")))))),solve(ᵀ∗,GDB2,Select("varA")))→Select("varC")
:solve()
JK, it doesn't have to be that unreadable. I just wanted to show what you could do if you really wanted to. (Yes, that means you can nest as much as you want, limited only by the amount of memory available.) A normal person might do something more like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
:#Axiom(CPLXMATH) .obviously
:Buff(9)→GDB2 .declare constants
:Buff(9)→GDB4
:2→float{GDB2} .initialize constants
:4→float{GDB4}
:Select("varA")→A .yes you can do that
:Select("varB")→B
:Select("varC")→C
:solve(ᵀ√(,solve(ᵀ‒,solve(ᵀ²,B),solve(ᵀ∗,GDB4,solve(ᵀ∗,A,C))))→D
:solve(ᵀ-,B)→B .pre-calculate stuff
:solve(ᵀ∗,GDB2,A)→A
:solve(ᵀ/,solve(ᵀ+,B,D),A)→Select("varD")
:solve(ᵀ/,solve(ᵀ‒,B,D),A)→Select("varE")
:solve()

Let's return the result in Ans instead of D and E.

1
2
:(-B+{1,-1}√(B²+i²4AC))/(2A)
i²=-1, but it allows the result to be complex regardless of mode. Similarly, complex constants are used below, with no i component, in order to allow complex answers in any mode.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
:#Axiom(CPLXMATH)
:[015D]"TEMP"→Str1LT .[015D] must be used instead of the ᴸ before a list in the current version of Axe
:[0C80200000000000000C8000000000000000]→GDB2 .still 2, but complex
:[0C80400000000000000C8000000000000000]→GDB4 .complex floating point 4
:Select("varA")→A
:Select("varB")→B
:Select("varC")→C
:solve(ᵀ√(,solve(ᵀ‒,solve(ᵀ²,B),solve(ᵀ∗,GDB4,solve(ᵀ∗,A,C))))→C .we don't need C anymore
:solve(ᵀ-,B)→B .pre-calculate stuff
:solve(ᵀ∗,GDB2,A)→A
:DelVar Str1LT .Delete ᴸTemp in case it already exists
:solve(ᵀ/,solve(ᵀ+,B,C),A)→Select(Str1LT,1)
:solve(ᵀ/,solve(ᵀ‒,B,C),A)→Select(Str1LT,2)
:Select(Str1LT)→Select("varAns") .yep, that's right
:DelVar Str1LT .no one needs ᴸTemp anymore
:solve() .we are done

Strange OP codes (used instead of ᵀ<token>)
ECEECFED0ED1ED2ED3ED4ED5ED6ED7ED8ED9EDAEDB
npv(irr(bal(∑Prn(∑Int➤Nom(➤Eff(dbd(lcm(gcd(randInt(randBin(sub(stdDev(
EDCEDDEDEEDFEE0EE1EE2EE3EE4EE5EE6EE7EE8EE9
variance(inString(normalcdf(invNorm(tcdf(Χ²cdf(Ϝcdf(binompdf(binomcdf(poissonpdf(poissoncdf(geometpdf(geometcdf(normalpdf(
EEAEEBEECEEDE89E8AE8BE8CE8DE8EE8FE90E91E92E93
tpdf(Χ²pdf(Ϝpdf(randNorm(conj(real(imag(angle(cumSum(expr(length(ΔList(ref(rref(Fill(

Update 0.1: Tutorial added.
Update 0.2: Major bugfix.
Update 0.3: Select( is replaced with get(. Key: seq(

*Warning: Please do not use RealMath unless you are absolutely sure that your code will never see anything that could posibly be complex. (unless you want corrupted mem, etc.) However, use it if you can, since it is smaller and faster.

* CPLXMATH.8Xv (0.87 KB - downloaded 29 times.)
* REALMATH.8Xv (0.75 KB - downloaded 26 times.)
* fpmath-0.1.zip (32.13 KB - downloaded 30 times.)
* fpmath-0.2.zip (34.3 KB - downloaded 21 times.)
* fpmath-0.3.zip (118.15 KB - downloaded 10 times.)
« Last Edit: 02 August, 2012, 09:44:34 by jacobly » Logged
Deep Thought
So much to do, so much time, so little motivation
Administrator
LV13 Extreme Addict (Next: 9001)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 03:12:44
Date Registered: 19 May, 2009, 08:00:00
Location: The Universe
Posts: 7832


Total Post Ratings: +713

View Profile WWW
« Reply #1 on: 26 October, 2011, 01:19:45 »
0

I personally haven't had a use for it yet, but good work Smiley Using T to grab operations is genius!
Logged




Yeong
Eternally Young Scarlet Moon
LV12 Extreme Poster (Next: 5000)
************
Offline Offline

Gender: Male
Last Login: 14 June, 2013, 04:17:01
Date Registered: 15 October, 2010, 04:29:49
Location: Arden, NC
Posts: 3705


Total Post Ratings: +260

View Profile
« Reply #2 on: 26 October, 2011, 01:21:51 »
0

it looks awesome!
So Quad solver in Axe finally? Cheesy
Logged

Project Redemption....

My project progresses:HERE
My Pastebin stuffs:HERE
Check your rate: HERE
My Animations: HERE
Spoiler for Images :D:

ノ◕ヮ◕)ノ:・゚ PENGUIN WAVE!!:„ø¤º°¨ ¨°º¤KEEP THE PENGUIN GOING ¸„ø¤º°¨ ¨°º¤øº LETS GO PENGUIN !¤¤º°¨¨°º¤øº¤ø„¸¸ø¤º°¨„ ø¤º°¨¨°º
Deep Thought
So much to do, so much time, so little motivation
Administrator
LV13 Extreme Addict (Next: 9001)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 03:12:44
Date Registered: 19 May, 2009, 08:00:00
Location: The Universe
Posts: 7832


Total Post Ratings: +713

View Profile WWW
« Reply #3 on: 26 October, 2011, 01:22:09 »
0

Oh, I have a suggestion. Not sure how this would work, but why not merge Select() with float{} somehow, seeing as the latter's already used natively by Axe? Again, I have no idea how that would work, but if it could work that'd be awesome. It would mean one fewer token used up by an Axiom.

yeong, oh dear Big frown
« Last Edit: 26 October, 2011, 01:22:32 by Deep Thought » Logged




Yeong
Eternally Young Scarlet Moon
LV12 Extreme Poster (Next: 5000)
************
Offline Offline

Gender: Male
Last Login: 14 June, 2013, 04:17:01
Date Registered: 15 October, 2010, 04:29:49
Location: Arden, NC
Posts: 3705


Total Post Ratings: +260

View Profile
« Reply #4 on: 26 October, 2011, 01:23:24 »
0

did we already had one?
Logged

Project Redemption....

My project progresses:HERE
My Pastebin stuffs:HERE
Check your rate: HERE
My Animations: HERE
Spoiler for Images :D:

ノ◕ヮ◕)ノ:・゚ PENGUIN WAVE!!:„ø¤º°¨ ¨°º¤KEEP THE PENGUIN GOING ¸„ø¤º°¨ ¨°º¤øº LETS GO PENGUIN !¤¤º°¨¨°º¤øº¤ø„¸¸ø¤º°¨„ ø¤º°¨¨°º
jacobly
LV5 Advanced (Next: 300)
*****
Offline Offline

Last Login: Today at 02:52:09
Date Registered: 09 October, 2011, 01:53:09
Posts: 200

Topic starter
Total Post Ratings: +150

View Profile
« Reply #5 on: 26 October, 2011, 01:25:36 »
0

According the the almighty Quigibo Wink, that doesn't work yet.
Quote from: Quigibo
Unfortunately, you cannot re-define current Axe tokens in Axioms which is why you're getting that error, you can only overwrite unused tokens.

EDIT:
Oh, and I originally did use solve( for everything instead of Select(. The code may have been slightly unreadable. Big frown
Besides, Select( takes a string and float{ takes a pointer...
« Last Edit: 26 October, 2011, 01:31:34 by jacobly » Logged
FinaleTI
Believe in the pony that believes in you!
Coder Of Tomorrow
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: 02 June, 2013, 22:43:20
Date Registered: 04 June, 2010, 00:34:27
Location: Alteria
Posts: 1818


Total Post Ratings: +118

View Profile WWW
« Reply #6 on: 26 October, 2011, 01:51:21 »
0

Intriguing. Now, people really can write a CAS in Axe. Wink

Perhaps I should release the routine I made to convert a string to a real and store it in a real var, so it would make this even easier to use this library, as it doesn't require knowledge of the FP format.
« Last Edit: 26 October, 2011, 01:56:42 by FinaleTI » Logged





So, yeah, I have a blog now. Nothing special, just your average ghost town.

Spoiler for Projects:
Spoiler for Pokemon TI:
Map engine is going to be redone from scratch, since I was lacking in organization last time. With a project as big as Pokemon, planning and organization is key, so that will probably be the brunt of the work done on this project for the time being.

Spoiler for Nostalgia:
Being worked on. Nothing really new to put here, but it's being worked on.

Spoiler for Finale's Super Insane Tunnel Pack of Doom:
I will be combining Blur and Collision Course into a single gamepack.

Spoiler for Nostalgia Origins: Sky's Story:
Currently on hold. I am unsure of whether this will remain DCS7 Hybrid BASIC or if it will use Batlib, Grammer or perhaps Axe.
This may see more progress once a demo of Nostalgia is released.
Deep Thought
So much to do, so much time, so little motivation
Administrator
LV13 Extreme Addict (Next: 9001)
*
Offline Offline

Gender: Male
Last Login: Yesterday at 03:12:44
Date Registered: 19 May, 2009, 08:00:00
Location: The Universe
Posts: 7832


Total Post Ratings: +713

View Profile WWW
« Reply #7 on: 26 October, 2011, 02:12:07 »
0

Perhaps I should release the routine I made to convert a string to a real and store it in a real var, so it would make this even easier to use this library, as it doesn't require knowledge of the FP format.
This Axiom doesn't either, does it? Huh?
Logged




FinaleTI
Believe in the pony that believes in you!
Coder Of Tomorrow
LV10 31337 u53r (Next: 2000)
*
Offline Offline

Gender: Male
Last Login: 02 June, 2013, 22:43:20
Date Registered: 04 June, 2010, 00:34:27
Location: Alteria
Posts: 1818


Total Post Ratings: +118

View Profile WWW
« Reply #8 on: 26 October, 2011, 02:16:22 »
0

Perhaps I should release the routine I made to convert a string to a real and store it in a real var, so it would make this even easier to use this library, as it doesn't require knowledge of the FP format.
This Axiom doesn't either, does it? Huh?
If you want to create an FP number like -0.145 in the program, I believe you have to create it using hex.
I believe the Axiom only adds math functions, not creating or displaying non-integer FP numbers.
Logged





So, yeah, I have a blog now. Nothing special, just your average ghost town.

Spoiler for Projects:
Spoiler for Pokemon TI:
Map engine is going to be redone from scratch, since I was lacking in organization last time. With a project as big as Pokemon, planning and organization is key, so that will probably be the brunt of the work done on this project for the time being.

Spoiler for Nostalgia:
Being worked on. Nothing really new to put here, but it's being worked on.

Spoiler for Finale's Super Insane Tunnel Pack of Doom:
I will be combining Blur and Collision Course into a single gamepack.

Spoiler for Nostalgia Origins: Sky's Story:
Currently on hold. I am unsure of whether this will remain DCS7 Hybrid BASIC or if it will use Batlib, Grammer or perhaps Axe.
This may see more progress once a demo of Nostalgia is released.
ztrumpet
The Rarely Active One
LV13 Extreme Addict (Next: 9001)
*************
Offline Offline

Gender: Male
Last Login: 11 June, 2013, 05:10:51
Date Registered: 08 November, 2009, 21:10:12
Location: Michigan
Posts: 5688


Total Post Ratings: +360

View Profile
« Reply #9 on: 26 October, 2011, 02:41:22 »
0

This is really awesome!  Thanks for making this wonderful library. Cheesy
Logged

AngelFish
This is my custom title
Administrator
LV12 Extreme Poster (Next: 5000)
*
Offline Offline

Gender: Male
Last Login: Today at 01:01:26
Date Registered: 15 August, 2010, 09:18:54
Posts: 3192


Total Post Ratings: +222

View Profile
« Reply #10 on: 26 October, 2011, 02:49:58 »
0

* Qwerty.55 checks the posting date

shocked

I was planning on asking for help with floating point in Axe tonight. Awesome timing.
« Last Edit: 26 October, 2011, 02:50:27 by Qwerty.55 » Logged

∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ
alberthrocks
Coder Of Tomorrow
LV8 Addict (Next: 1000)
*
Offline Offline

Last Login: 11 June, 2013, 19:34:32
Date Registered: 01 May, 2010, 16:51:27
Posts: 743

Total Post Ratings: +88

View Profile
« Reply #11 on: 26 October, 2011, 03:39:53 »
0

That is.... AMAZING! O_O The impossible is now done! Cheesy (Well, not impossible, just hard.)
I guess this is a good time to revive the Z80 CAS topic? Cheesy

Also, I agree with the above suggestions of making the numbers easy to parse - we should use relatively simple syntax to make it work.

Before a CAS could be made, the following needs to occur:
1) String -> FP number
2) FP number -> String
3) Display FP number on arbitrary display buffer at certain position (pref. #2)
4) Huh?

I might still have code to print FP numbers, but it's in BASIC and requires... FP functions? Tongue (Specifically, log, int(), fPart(), and iPart().) If you would like to use it, tell me and I'll try to dig it out of a calc backup that is in a dead HDD backup... Tongue
Logged

Alternate "New" IRC post notification bot (Newy) down? Go here to reset it! http://withg.org/albert/cpuhero/

Withgusto Networks Founder and Administrator
Main Server Status: http://withg.org/status/
Backup Server Status: Not available
Backup 2/MC Server Status: http://mc.withg.org/status/

Activity remains limited due to busyness from school et al. Sorry! Sad Feel free to PM, email, or if you know me well enough, FB me if you have a question/concern. Smiley

Don't expect me to be online 24/7 until summer. Contact me via FB if you feel it's urgent.


Proud member of ClrHome!

Spoiler for "My Projects! :D":
Projects:

Computer/Web/IRC Projects:
C______c: 0% done (Doing planning and trying to not forget it Tongue)
A_____m: 40% done (Need to develop a sophisticated process queue, and a pretty web GUI)
AtomBot v3.0: 0% done (Planning stage, may do a litmus test of developer wants in the future)
IdeaFrenzy: 0% done (Planning and trying to not forget it Tongue)
wxWabbitemu: 40% done (NEED MOAR FEATURES Tongue)

Calculator Projects:
M__ C_____ (an A____ _____ clone): 0% done (Need to figure out physics and Axe)
C2I: 0% done (planning, checking the demand for it, and dreaming Tongue)
Keoni29
LV9 Veteran (Next: 1337)
*********
Offline Offline

Gender: Male
Last Login: Today at 00:02:37
Date Registered: 15 March, 2011, 16:23:33
Location: The Netherlands
Posts: 1159


Total Post Ratings: +156

View Profile WWW
« Reply #12 on: 26 October, 2011, 15:39:29 »
0

* Qwerty.55 checks the posting date

shocked

I was planning on asking for help with floating point in Axe tonight. Awesome timing.
Maybe he learned how to make axioms elsewhere? Maybe he has another account?
« Last Edit: 26 October, 2011, 15:39:51 by Keoni29 » Logged


Spoiler for Hidden:
Last signature update 10:55 april 22nd 2013
Xeda112358
Xombie. I am it.
Coder Of Tomorrow
LV12 Extreme Poster (Next: 5000)
*
Offline Offline

Last Login: Today at 04:03:27
Date Registered: 31 October, 2010, 08:46:36
Location: Land of Little Cubes and Tea, NY
Posts: 3781


Total Post Ratings: +614

View Profile
« Reply #13 on: 26 October, 2011, 15:45:49 »
0

Some assembly code can be whipped up to convert between string and FP, but I am not going to commit myself to that task Big smile
Logged



Grammer Download (2.29.04.12)
Latest update (possibly incomplete)
My pastebin
Spoiler for FileSyst:
FileSyst is an application that provides a folder and filesystem for the TI-83+/84+ calculators. It is designed to be easy to access and use in BASIC, and it can be used to access game files and save data, or to create a command prompt, among other things:

Spoiler for Graphiti:
This is a graph explorer for graph theory. It will require lots of work to finish. Currently you can:
Add/delete vertices
Add edges (direction not shown, but they are directed)
Arrange vertices in a circle (in the future, you will be able to define levels of rings and the number of nodes in each)
Create complete graphs quickly

Plans:
Add adjacency matrix viewer
Deleting edges
Multiple graphs support
Arrows for directed graphs
Planarity testing
Matrix operations
Weighted edges
Chromatic polynomials
Chromatic numbers

Spoiler for Stats:

Samocal             [o---------]
Virtual Processor   [o---------]
EnG                 [oo--------]
Grammer             [ooo-------]
AsmComp             [ooo-------]
Partex              [oooo------]
BatLib              [oooooooo--]
Grammer82           [----------]
Grammer68000        [----------]


Pseudonyms:  Zeda, Xeda, Thunderbolt
Languages:   English, français
Programming: z80 Assmebly
             Grammer
             TI-BASIC (83/84/+/SE, 89/89t/92)
Known For:   -Creator of the Grammer programming language
              (Winning program of zContest2011)
             -BatLib- One of the most feature packed libraries for BASIC programmers available
              with over 100 functions and a simple programming language
             -Learning to program z80 in hexadecimal before using an assembler (no computer was
              available!)
╔═╦╗░╠═╬╣▒║ ║║▓╚═╩╝█


Keoni29
LV9 Veteran (Next: 1337)
*********
Offline Offline

Gender: Male
Last Login: Today at 00:02:37
Date Registered: 15 March, 2011, 16:23:33
Location: The Netherlands
Posts: 1159


Total Post Ratings: +156

View Profile WWW
« Reply #14 on: 26 October, 2011, 15:53:21 »
0

I have seen some AXE programmes using strings to export images or tilemaps. How is that possible?
Logged


Spoiler for Hidden:
Last signature update 10:55 april 22nd 2013
Pages: [1] 2   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.497 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.