April 30, 2024, 10:22:22 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Differences between INT's, UINT's etc.

Started by Andy, May 15, 2016, 01:08:32 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

jalih

Quote from: Andy on May 21, 2016, 05:38:25 AM
So now I have to work on numbers bigger than 4294967295.... that's the next challenge.

With little inline assembly, using the FPU to store number as packed BCD number and then converting from the packed BCD format to a null-terminated alphanumeric string gives you 18 digits precision...

Andy


I was also coming to the conclusion that assembly might be needed at this point.

Assembly was the first language I was shown at school when I was 13, and I touched it again at university - however I cannot remember now how to program in it.

Guess this could take a long time to get past this point - unless someone can help.  ???

Thanks,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

jalih

Quote from: Andy on May 23, 2016, 10:09:25 PM
Assembly was the first language I was shown at school when I was 13, and I touched it again at university - however I cannot remember now how to program in it.

Here is my first attempt for using FPU and BCD numbers to replace STR$...


int64 i
i = -123456789012345678q 'Negative number with 18 digits

string s

_asm
  segment .data
  num dt 0.0
  segment .text

  push esi
  push edi

  finit
  fild qword[$i]
  fbstp [num]

  lea esi,[num+9]
  lea edi,[$s]
  mov eax, 0
  fwait

  mov al, [esi]
  dec esi
  or al, al
  jns @@1
  mov al,'-'
  stosb
@@1:
  mov ecx, 8
@@2:
  mov al, [esi]
  dec esi
  or al,al
  jnz @@3
  dec ecx
  jnz @@2

  mov al, "0"
  stosb
  jmp done
@@3:
  test al, 0f0h
  jz digit2
digit1:
  ror ax, 4
  add al, 30h
  stosb
  shr ax, 12
digit2:
  add al, 30h
  stosb
  mov al, [esi]
  dec esi
  jz done

digit12: 
  mov ah, al
  shr al, 4
  and ah, 0fh
  add ax, 3030h
  stosw
  mov al, [esi]
  dec esi
  dec ecx
  jnz digit12

done:
  mov al, 0
  stosb

  pop edi
  pop esi
_endasm


print s

do:until inkey$ <> ""



Brian

Wow - goes right over my head! But well done!

Brian

srvaldez

hello jalih
your program does not work with the full range of int64, I imagine it would take some effort to make it work as fbstp only outputs 18 digits.

Andy

June 01, 2016, 11:21:56 PM #30 Last Edit: June 02, 2016, 07:49:18 AM by Andy
Jalih,

I like the attempt!

However, as I've said before you cannot push a number larger than 18446744073709551615 (16 F's) to a uint64, It's too big.

And in any case, how on earth could you "add" a letter to a number?

What's my obsession with the number 18446744073709551615? - it represents the largest value a qword can have in the windows registry 0xFFFFFFFFFFFFFFFF.

However you may want to work with a number larger than 18446744073709551615 and then +, -, *, / will not work.

We need C's equivalent of a long or long long variable to work with such large numbers.

If you want to work with numbers greater than 18446744073709551615, you need to use my StringMap library, here you have +, -, *, / functions, but it does however need the number as a string, and returns a string for any maths operations used as the result  - that's the best I can do, and it took me a very very long time to write these functions (so you don't have to).

Thanks,
Andy.
:)
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.