# LONG2NUM vs LONG2FIX

**URL:** <https://www.ruby-forum.com/t/long2num-vs-long2fix/93267>\
**Category:** Ruby\
**Created:** [April 30, 2007, 7:46am UTC](https://www.ruby-forum.com/t/long2num-vs-long2fix/93267 "2007-04-30T07:46:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [April 30, 2007, 7:46am UTC](https://www.ruby-forum.com/t/long2num-vs-long2fix/93267/1 "2007-04-30T07:46:06Z")

</div>

what’s the difference about “LONG2NUM and LONG2FIX” in ruby c api?  
why not “return LONG2FIX after FIX2LONG”??  
thanks.

ruby source file(numeric.c):  
/\*

- call-seq:
- 

```
fix.abs -> aFixnum

```

- 
- Returns the absolute value of _fix_.
- 
- 

```
-12345.abs #=> 12345

```

- 

```
12345.abs #=> 12345

```

- 

\*/

static VALUE  
fix\_abs(fix)  
VALUE fix;  
{  
long i = FIX2LONG(fix);

```
if (i < 0) i = -i;

return LONG2NUM(i);

```

}

---

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [April 30, 2007, 8:00am UTC](https://www.ruby-forum.com/t/long2num-vs-long2fix/93267/2 "2007-04-30T08:00:13Z")

</div>

Haoqi H. wrote:

> what’s the difference about “LONG2NUM and LONG2FIX” in ruby c api?

LONG2FIX will truncate into a Fixnum (a 31 bit signed integer). LONG2NUM  
will convert to Bignum (arbitrary precision integer) if necessary.

> why not “return LONG2FIX after FIX2LONG”??  
> thanks.

(-2**30).class # =\> Fixnum  
(2**30).class # =\> Bignum  
(-2\*\*30).abs.class # =\> Bignum

---

<div class="post-metadata">

**Author:** ![haoqi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@haoqi](https://www.ruby-forum.com/u/haoqi)\
**Post date:** [May 1, 2007, 7:47am UTC](https://www.ruby-forum.com/t/long2num-vs-long2fix/93267/3 "2007-05-01T07:47:17Z")

</div>

Joel VanderWerf wrote:

> Haoqi H. wrote:
> 
> > what’s the difference about “LONG2NUM and LONG2FIX” in ruby c api?
> 
> LONG2FIX will truncate into a Fixnum (a 31 bit signed integer). LONG2NUM  
> will convert to Bignum (arbitrary precision integer) if necessary.
> 
> > why not “return LONG2FIX after FIX2LONG”??  
> > thanks.
> 
> (-2**30).class # =\> Fixnum  
> (2**30).class # =\> Bignum  
> (-2\*\*30).abs.class # =\> Bignum

Thank you~
