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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Storing only the mantissa

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
thentangler Posted - 07/14/2011 : 5:36:43 PM
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
8   L A T E S T    R E P L I E S    (Newest First)
DataConv Posted - 08/28/2011 : 09:29:56 AM
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...
Hideo Fujii Posted - 08/26/2011 : 11:35:23 AM
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
DataConv Posted - 08/24/2011 : 2:34:07 PM
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...
thentangler Posted - 08/18/2011 : 6:42:15 PM
Wow,
Thank you Mr Fuji.
I will try that...
Hideo Fujii Posted - 08/02/2011 : 2:05:12 PM
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
thentangler Posted - 07/27/2011 : 3:42:56 PM
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?
minimax Posted - 07/27/2011 : 02:19:05 AM
There is no such ready-made function in Origin.

You will have to write your own to get the mantissa.
thentangler Posted - 07/15/2011 : 6:39:17 PM
Somebody???

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000