Author Topic: Math  (Read 6236 times)

0 Members and 1 Guest are viewing this topic.

SirCmpwn

  • Guest
Math
« on: December 01, 2010, 06:20:41 pm »
Hello,
Can we discuss methods of doing signed math in decimal, like TIOS does, in z80 assembly?

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Math
« Reply #1 on: December 01, 2010, 06:31:00 pm »
You're addicted to calcs and omni when you have multiple links to this type of material bookmarked:

http://www.andreadrian.de/oldcpu/Z80_number_cruncher.html#mozTocId181827

http://z80.info/index.html (scroll down)

http://www.programmers-corner.com/tutorial/31

That's what I have for the z80, let alone the ARM stuff.
« Last Edit: December 01, 2010, 06:31:17 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Math
« Reply #2 on: December 01, 2010, 06:31:58 pm »
SirCmpwn, you're starting to make the maths engine, like 1+1? I know that maths in Assembly is really difficult, so good luck!

SirCmpwn

  • Guest
Re: Math
« Reply #3 on: December 01, 2010, 06:32:53 pm »
Not yet, but I'm reading up.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Math
« Reply #4 on: December 01, 2010, 06:36:31 pm »
Not yet, but I'm reading up.

Good luck then. I like Ti-OSs math stuff, so I'd ike them to be similar

SirCmpwn

  • Guest
Re: Math
« Reply #5 on: December 01, 2010, 06:41:13 pm »
Thanks for the links, Qwerty.55

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Math
« Reply #6 on: December 01, 2010, 06:52:12 pm »
You're welcome. One request though: Don't try to do that bloody mathprint thing. It's really annoying.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

SirCmpwn

  • Guest
Re: Math
« Reply #7 on: December 01, 2010, 06:53:44 pm »
I was going to have it as an option.  Don't worry, I would do it much better than TI.
« Last Edit: December 01, 2010, 06:53:56 pm by SirCmpwn »

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Math
« Reply #8 on: December 01, 2010, 07:59:47 pm »
And much more stable.  I'm not sure how TIOS parses stuff. I know on higher languages, I try and make some sort of tree structure, and take what I have and go backward.  Will this be able to simplify polynomials? Is this completely part of the kernel, or is there like a "math app" type thing?

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Math
« Reply #9 on: December 01, 2010, 09:29:42 pm »
Hello,
Can we discuss methods of doing signed math in decimal, like TIOS does, in z80 assembly?
Here's how the TI-OS does it (you'll probably want something similar, but with a more optimized implementation of course).

Floating point values are stored in 9 bytes, using a scientific notation form. The first byte is the sign byte (Bit 7 is set if the value is negative, reset if positive. The rest of the byte is used for other miscellaneous info like the complex number identifier). The second byte is the exponent, which is the power of 10 in the scientific notation form (plus 128). Bytes 3-9 hold the significand of the number in binary-coded decimal. The decimal point goes between the first and second digit (the first digit can be 0 only if the entire value is 0).

Okay, now for a real-world example -- representation of the number -15.125:
(in hexadecimal) 80 81 15 12 50 00 00 00 00
which is -1.5125000000000 x 10^(129-128)

To add two floating point numbers, you must shift the significand of the smaller value to the right by one digit and increase its exponent until it has the same exponent as the larger value. Then you can add together both 7-byte numbers (using the DAA instruction after each addition to adjust the result to be correct for BCD math)
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman