Single precision floating point operation

Hi I have done double precision floating point operations with matlab Now I have to do single precision. But I dont know how to do this in matlab what problem I am facing is suppose 1.234e50 this number is within range for double precision. But in case of single it is infinity so op1 = 2 op2 = 1.234e50 op1 / op2 = 1.620745542949757e-050 in case of double which i am getting directly. But in case of single precision it should be zero.
So in matlab is there any command through which we can set precision as single

답변 (1개)

Jos (10584)
Jos (10584) 2013년 12월 10일

0 개 추천

Use SINGLE to convert values to single precision
x = 1.234e50
z1 = 2/x
z2 = single(2/x)
whos

댓글 수: 2

seeker_123
seeker_123 2013년 12월 10일
thank you
yes. But in that case conversion is after calculation. But in some cases after conversion results are valid (means within range of single precision) but if input is out of range then in single precision should not get results. like 2/3.40282366E38 here op2 is actually overflow in single precision so it is considered as infinity in single precision and output should be zero But if it is done like this single(2/x) = 5.8774718e-039 It is because actual calc is done under double precision only
so still problem is there.
x = single(1.234e50)
z1 = single(2)/x

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2013년 12월 10일

댓글:

2013년 12월 10일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by