flat assembler
Message board for the users of flat assembler.

Index > Windows > Creating a constant float from a string

Author
Thread Post new topic Reply to topic
NanoBytes



Joined: 02 Jun 2011
Posts: 57
Location: Iowa, United States
NanoBytes 02 Oct 2011, 18:24
Hey guys, I realize that what I am asking is daunting and fairly complex (As I have learned from the past week or so). I am trying to create a procedure that will alow me to simulate a constant float throught the use of strings
Code:
stdcall makeFloat, "3.21"    

The process that I was is as follows: first read the integral part of the string, which is "3", load it into the floating point stack, then read the decimal part and add it onto the integral part of the number. Well, this is all theoretical, the task was to complex for me to create a working process, and I was woundering if you guys could help me. My issue is with the decimal part, this part needs to be read backwards, meaning that you start reading from the end of the string and move tward the begining. Here is an example
Code:
Value = (1)+Value*0.1 = 1.0
Value = (2)+Value*0.1 = 2.1
Value = Value*0.1 = 0.21
    

The numbers in parenthesis are the numbers read from the string. After the loop is over you would, in theory, add the value onto the integer value previosly read. Like I said, the task is complex, could any of you provide me with a procedure that will do this, or al least the floating point part of the string. Confused

_________________
He is no fool who gives what he cannot
keep to gain what he cannot loose.
Post 02 Oct 2011, 18:24
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 02 Oct 2011, 18:56
Quote:

My issue is with the decimal part, this part needs to be read backwards
Why is that? Wouldn't the following pseudo-code do the work as well?
Code:
num= load_integer_part()
divisor = 10.0
for each fractional digit in forward direction do
  num = num + ascii_to_float(digit) / divisor
  divisor = divisor * 10
od    
I don't guarantee high quality conversions though, check fasm's sources to get a better implementation.
Post 02 Oct 2011, 18:56
View user's profile Send private message Reply with quote
NanoBytes



Joined: 02 Jun 2011
Posts: 57
Location: Iowa, United States
NanoBytes 02 Oct 2011, 20:22
Hmmm, I like that, much simpler than I presumed, thanks, Ill try it Smile
Post 02 Oct 2011, 20:22
View user's profile Send private message Send e-mail Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4020
Location: vpcmpistri
bitRAKE 02 Oct 2011, 20:25
Using FBLD / FBSTP would be an easy lesser alternative. Multiple digits can be converted simultaneously and then a single division used to scale integer based on decimal point.

http://www.website.masmforum.com/tutorials/fptute/fpuchap6.htm
Post 02 Oct 2011, 20:25
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.