The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Storing only the mantissa
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

thentangler

USA
Posts

Posted - 07/14/2011 :  5:36:43 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 8.1 and Service Release 3, Operating System: XP

Hi,
I wanted to know how to take only the mantissa or coefficient of a number in originlab. For example if I have 2.34e-7, I want to store only 2.34 in a variable and discard the exponent.
Any help will be appreciated.
Thank You

thentangler

USA
Posts

Posted - 07/15/2011 :  6:39:17 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Somebody???
Go to Top of Page

minimax

355 Posts

Posted - 07/27/2011 :  02:19:05 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
There is no such ready-made function in Origin.

You will have to write your own to get the mantissa.
Go to Top of Page

thentangler

USA
Posts

Posted - 07/27/2011 :  3:42:56 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Ok, How would I go about doing it?
Would I have to access the addresses which stores the sign, bit and exponent of each number?
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 08/02/2011 :  2:05:12 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi thentangler,

Maybe a bit off-topic, but if you want to change ALL values in a worksheet column, not for a single variable, you can run the following script:
cn=2; //column number
nd=12; //number of digits
wks.col$(cn).subformat=2; //set to Display:Scientific
wks.col$(cn).digits=nd; //set Digits
wks.col$(cn).format=2; //set to Format:Text
for(ii=1;ii<=wks.col$(cn).nRows;ii++) {
  %A=col($(cn))[ii]$;
  col($(cn))[ii]$=%[%A,'E']; //Remove exponent
}
wks.col$(cn).format=1; //set to Format:Numeric
wks.col$(cn).digits=nd; //set Digits again

--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 08/02/2011 6:05:46 PM
Go to Top of Page

thentangler

USA
Posts

Posted - 08/18/2011 :  6:42:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Wow,
Thank you Mr Fuji.
I will try that...
Go to Top of Page

DataConv

Germany
60 Posts

Posted - 08/24/2011 :  2:34:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
To extract only the mantissa you can use the following algorithm:
double va=2.34e-7;
double vb=va/(10^int(log(abs(va)+(1-abs(sign(va))))));

Description: The 'core' is the division of the number va by its exponent (on base 10). This is accomplished by building the log10 of the number, truncate it to a integer and built the power of 10 of it. Now 2 pitfalls exist: First, the log of a negative number is not defined, therefore the absolute value - which is always positiv - is provided for the log function. Second, the special case of a zero value must be handled. Therefore the (1-abs(sign())) part. In the normal case of a non-zero value, this produces a zero - the value is unchanged. In the case of a zero indeed, this constuct produces a value to 1, ensuring, that the log function has a valid number to convert. And since zero divided by anything else than zero gives again zero, all normal cases are handled...
Go to Top of Page

Hideo Fujii

USA
1582 Posts

Posted - 08/26/2011 :  11:35:23 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
That's wonderful, and thank you DataConv!

Anyway, a little bit puzzling result...
>> double va1=123.456e-10;
>> double va2=123.456e+10;
>> double vb1=va1/(10^int(log(abs(va1)+(1-abs(sign(va1))))));
>> double vb2=va2/(10^int(log(abs(va2)+(1-abs(sign(va2))))));
>> vb1=;
  vb1=0.123456
>> vb2=;
  vb2=1.23456


How can we deal with this?

--Hideo Fujii
OriginLab
Go to Top of Page

DataConv

Germany
60 Posts

Posted - 08/28/2011 :  09:29:56 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Mea culpa - didn't test the function enough! Here's the function providing the correct data:
va/10^int((log(abs(va+1-abs(sign(va)))))-1+sign(1+sign(abs(va)-1)))
To admit, it's a bit more complex. But it handles exponents up /down to the largest/lowerst number. A simpler approach on the formula given in the previous post would have been to add a certain positive integer before the int() function and substract it directly from the result thereof. But that would have been just an workaround with another pitfall.
The formula given should now provide the values wanted...
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000