Hi i have ptoblem with this code, it dosen`t work corectly with big data(number). For example p1=< 28623421, sqrt1 >= p1. Can eny one help me?
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
Active-HDL designHi i have ptoblem with this code, it dosen`t work corectly with big data(number). For example p1=< 28623421, sqrt1 >= p1. Can eny one help me?
Nazar R. wrote: > Can eny one help me? 1.) Read the manual of the edit box:
2.) Use indention and advanced formatting to get a readable code.
3.) What data types have the used signals? Integer? Real? > p1=< 28623421 What is "p1"? Is it the input parameter for the incomplete function or the unknown process? > For example p1=< 28623421, sqrt1 >= p1. What does that mean? What do you expect? What do you get instead? And HOW do you get that? Simply attach the complete *.vhd file... p1 is a input data, real character, as the sqrt1 value it`s all the part of math expression, in this part i have problem with get sqrt function Nazar R. wrote: > it dosen`t work corectly with big data(number). For example p1=< > 28623421, sqrt1 >= p1. Can eny one help me? I suppose you simply have a problem with the number of significant digits of a real number. See that: http://codepad.org/s4xolHhg no you`a wrone. i know how to write real data type. this part of code must work with real type because sqrt function work only on this type i have just a code problem with loop statment Nazar R. wrote: > this part of code must work with real type What figures/value/nubmers have those parameters? Or the other way: show your complete code and the corresponding test bench. Otherwise we will not get a point here... :-/ this is my diagram value, parameters i wrote uper this page. this p1.. you need just put into the program > while sqrt(sqrt1+k1*p1) mod 1.0 /= 0.0
Thats the problem: never ever check real values for equality...
why? if you try to write this sentens into the paper and do some math you have tru answer. in this line i do some chek, if sqrt1... after do mod operation exit the 0 state
Guest
#4390050
mod is defined for integers but not for real. but it works for real type isn`t?
Guest
#4390073
Nazar R. wrote: > but it works for real type isn`t? Check it out for yourselves, I think "x mod 1" gets always zero : https://en.wikipedia.org/wiki/Modulo_operation out of the mist wrote: > mod is defined for integers but not for real. Only in C... But look at this: http://codepad.org/1q85mdCr A float value nearly never is something like .0000000! Its more something like .00001 or .999999 Nearly never the result of that operation will be 0.0
Guest
#4390078
Lothar M. wrote: > out of the mist wrote: >> mod is defined for integers but not for real. > Only in C... > No, http://www.csee.umbc.edu/portal/help/VHDL/operator.html Have a close look for the math_real package: https://standards.ieee.org/downloads/1076/1076.2-1996/math_real.vhdl
Guest
#4390097
Hi Nazar, sqrt(sqrt1) mod 1.0 is almost ALWAYS unequal 0.0 if sqrt1 is a floating point number. Think about it. Try 1.0 mod 1.0 and 0.9999999999 mod 1.0 and let us know the result thats a point to catch the number when sqrt1 have 0.0. in my work i use real type bacause i use sqrt operators a lot of time, thets why i convert all of my variables to real from integer type. all operations in the my model give me result in some sing like that 100.0, 152.0, 343558137.0 Martin wrote: > mod 1.0 is almost ALWAYS unequal 0.0 Or the other way: NEVER EVER compare a float value to equality Even if two float numbers "look" the same, they may be different: http://codepad.org/FO8DdkGk Nazar R. wrote: > all operations in the my model give me result in some sing like that > 100.0, 152.0, 343558137.0 No, they don't. Think about that, its a "problem" of how a real value is defined in IEEE 754. write in the calc 123 mod 1 and you have 0 but if you input 123.5 exit number is cheged. f**ck i dont know how discribe you my problem in the line sqrt(sqrt1+k1*p1) outputs may take value like 12.5, 1427.333. thets why i wrote mod 1 i must get full number without floating data *.45 Nazar R. wrote: > write in the calc In which one? > 123 mod 1 The mod function is NOT the problem here. > i dont know how discribe you my problem Looks alike... Nazar R. wrote: > all operations in the my model give me result in some sing like that > 100.0, 152.0, 343558137.0 Where do you see this values? For those .0 values have a look there: http://codepad.org/SlmEEkho You CANNOT compare a float number for equality... do you have active-hdl? Nazar R. wrote: > do you have active-hdl? Yes. Active HDL also uses the IEE 754 format. And therefore it also has the same restrictions... > do you have active-hdl? But as I already said several times: post your complete VHDL file (as a *.vhd or *.vhdl file pls!) and the test bench so everybody else can test your specific problem on his simulator. You can attach several files to one post... sorry i attach only bench file before > use IEEE.std_logic_unsigned.all; > use IEEE.std_logic_signed.all; > use ieee.numeric_std.all; > use IEEE.std_logic_arith.all; Ouch, ouch, ouch, ouch... EITHER use the use numeric_std (best and preferred choice) OR use those two: std_logic_signed and std_logic_arith OR use those two: std_logic_unsigned and std_logic_arith BUT do NOT use all of them together. Otherwise you have multiple type definitions and therfore sometimes very weird behaviour... Nazar R. wrote: > sorry i attach only bench file before A test bench usually is a *.vhd module WITHOUT ports in the entity. I will have a look at that tomorrow, now I'm away for the night... ;-)
Guest
#4390189
The entity has only one input but no output. You use conflicting IEEE packages. But the main problem is comparing float as Lothar has told you. Will the compare for equality ever return true? When? Only when it is exactly equal which might be very rare. You could compare if the float value is in a given range. E.g. if the value is greater 0.0 and smaller 0.1. This will never happen:
> exit when sqrt(sqrt1+k1*p1) mod 1.0 > 1.0;
Something mod 1.0 is always less then 1.0
Therefore this "exit" is useless and obsolete.
I took your code and transferred it into a little bit more handy test
bench. My conclusion: I can se no sense in those calculations. With the
values in the code I have 1.5 million loop iterations...
So the big question is:
What should this code do? Whats the origin of this code? Whats its
purpose?
You may also try this in your simulator:
Think about the results... So, let's again. I am engaged in developing advanced algorithm Rabin among Atstsdf. Part of my code should find the square root of a number. Do I have to check this number due to the fact that this number must then be multiplied by the transaction module and there should get an integer. small numbers I come out all right, here's an example I attach a file, it should just run. I ask if large numbers fixate the process of calculating and never stops Nazar R. wrote: > I am engaged in developing advanced algorithm Rabin among Atstsdf. Must this code be implemented on a FPGA in future? Then forget about real... > here's an example I attach a file, it should just run. And what should happen? > here's an example I attach a file, it should just run. Attach a second one that doesn't "run". And tell how you can see that... > exit when sqrt(sqrt1+k1*p1) mod 1.0 < 1.0; Something mod 1.0 is ALWAYS less then 1.0, so here the loop will ALWAYS be terminated... Did you read the post https://embdev.net/topic/384548#4390186 Did you understand it? Let me say it this way: I've shown you some major design flaws and you ignored all of that hints. I've also shown you a way to set up a little bit more "talky" test bench and you dig further on with your code. What do you expect as "help"? ReplyPlease log in before posting. |