Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Conversions Library

Name: Anonymous 2011-04-20 21:50

const double Pi                    = 3.14159265358979323846264;
const double TWO_Pi                = Pi*2.0;
const double HALF_Pi            = Pi/2.0;
const double QUARTER_Pi            = Pi/4.0;
const double Deg2Rad            = Pi/180.0;
const double Rad2Deg            = 180.0/Pi;
const float  fDeg2Rad            = static_cast(Deg2Rad);
const float  fRad2Deg            = static_cast(Rad2Deg);
const double OneThird            = 1.0/3.0;
const double One3point6th        = 1.0/3.6;
const double OneTwelfth            = 1.0/12.0;
const double OneThirtysixth        = 1.0/36.0;
const double One1760th            = 1.0/1760;
const double One5280th            = 1.0/5280;
const double One63360th            = 1.0/63360.0;
const double One25Pt4th            = 1.0/25.4;                // 0.0393700787401575        mm -> inches
const double One2Pt54th            = 1.0/2.54;                // 0.393700787401575        cm -> inches
const double OnePt0254th        = 1.0/0.0254;            // 39.3700787401575            m  -> inches
const double OnePt0000254th        = 1.0/0.0000254;        // 39370.0787401575            km -> inches
const double One2Pt20462262185th= 1.0/2.20462262185;    // 0.453592369999748        Lbs-> Kg
const double One304Pt8th        = 1.0/304.8;            // 0.00328083989501312        mm -> feet
const double One30Pt48th        = 1.0/30.48;            // 0.0328083989501312        cm -> feet
const double OnePt3048th        = 1.0/.3048;            // 3.28083989501312            m  -> feet
const double OnePt0003048th        = 1.0/.0003048;            // 3280.83989501312            km -> feet
const double One914Pt4th        = 1.0/914.4;            // 0.00109361329833771        mm -> yards
const double One91Pt44th        = 1.0/91.44;            // 0.0109361329833771        cm -> yards
const double OnePt9144th        = 1.0/.9144;            // 1.09361329833771            m  -> yards
const double OnePt0009144th        = 1.0/.0009144;            // 1093.61329833771            km -> yards
const double One1609344th        = 1.0/1609344;            // 0.000000621371192237334    mm -> Miles
const double One160934Pt4th        = 1.0/160934.4;            // 0.00000621371192237334    cm -> Miles
const double One1609Pt344th        = 1.0/1609.344;            // 0.000621371192237334        m  -> Miles
const double One1Pt609344th        = 1.0/1.609344;            // 0.621371192237334        km -> Miles
const double One4Pt44822th        = 1.0/4.44822161525;    // 0.224808943100241        Nt -> LbForce
const double OnePt737562th        = 1.0/0.7375621493;        // 1.35581794828961            FtLbs -> NtM
const double OnePt44704th        = 1.0/0.44704;            // 2.2369362920544            Mps -> Mph
const double One3Pt785411th        = 1.0/3.78541178401;    // 0.264172052357451        Liters -> Gallons

inline double Inches2Feet( const double &i )        { return i*OneTwelfth; }            // 1/12
inline double Inches2Yards( const double &i )        { return i*OneThirtysixth; }        // 1/36
inline double Inches2Miles( const double &i )        { return i*One63360th; }            // 1/63360.0
inline double Inches2MM( const double &i )            { return i*25.4; }
inline double Inches2CM( const double &i )            { return i*2.54; }
inline double Inches2Meters( const double &i )        { return i*.0254; }
inline double Inches2KM( const double &i )            { return i*.0000254; }

inline double Feet2Inches( const double &f )        { return f*12.0; }
inline double Feet2Yards( const double &f )            { return f*OneThird; }                // 1/3
inline double Feet2Miles( const double &f )            { return f*One5280th; }                // 1/5280
inline double Feet2MM( const double &f )            { return f*304.8; }
inline double Feet2CM( const double &f )            { return f*30.48; }
inline double Feet2Meters( const double &f )        { return f*0.3048; }
inline double Feet2KM( const double &f )            { return f*0.0003048; }

inline double Yards2Inches( const double &y )        { return y*36.0; }
inline double Yards2Feet( const double &y )            { return y*3.0; }
inline double Yards2Miles( const double &y )        { return y*One1760th; }                // 1/1760.0
inline double Yards2MM( const double &y )            { return y*914.4; }
inline double Yards2CM( const double &y )            { return y*91.44; }
inline double Yards2Meters( const double &y )        { return y*.9144; }
inline double Yards2KM( const double &y )            { return y*.0009144; }

inline double Miles2Inches( const double &mi )        { return mi*63360.0; }
inline double Miles2Feet( const double &mi )        { return mi*5280; }
inline double Miles2Yards( const double &mi )        { return mi*1760.0; }
inline double Miles2MM( const double &mi )            { return mi*1609344.0; }
inline double Miles2CM( const double &mi )            { return mi*160934.4; }
inline double Miles2Meters( const double &mi )        { return mi*1609.344; }
inline double Miles2KM( const double &mi )            { return mi*1.609344; }

inline double MM2CM( const double &mm )                { return mm*.1; }
inline double MM2Meters( const double &mm )            { return mm*.001; }
inline double MM2KM( const double &mm )                { return mm*.000001; }
inline double MM2Inches( const double &mm )            { return mm*One25Pt4th; }            // 0.0393700787401575
inline double MM2Feet( const double &mm )            { return mm*One304Pt8th; }            // 0.00328083989501312
inline double MM2Yards( const double &mm )            { return mm*One914Pt4th; }            // 0.00109361329833771
inline double MM2Miles( const double &mm )            { return mm*One1609344th; }            // 0.000000621371192237334

inline double CM2MM( const double &cm )                { return cm*10.0; }
inline double CM2Meters( const double &cm )            { return cm*.01; }
inline double CM2KM( const double &cm )                { return cm*.00001; }
inline double CM2Inches( const double &cm )            { return cm*One2Pt54th; }            // 0.393700787401575
inline double CM2Feet( const double &cm )            { return cm*One30Pt48th; }            // 0.0328083989501312
inline double CM2Yards( const double &cm )            { return cm*One91Pt44th; }            // 0.0109361329833771
inline double CM2Miles( const double &cm )            { return cm*One160934Pt4th; }        // 0.00000621371192237334

inline double Meters2MM( const double &m )            { return m*1000.0; }
inline double Meters2CM( const double &m )            { return m*100.0; }
inline double Meters2KM( const double &m )            { return m*.001; }
inline double Meters2Inches( const double &m )        { return m*OnePt0254th; }            // 39.3700787401575
inline double Meters2Feet( const double &m )        { return m*OnePt3048th; }            // 3.28083989501312
inline double Meters2Yards( const double &m )        { return m*OnePt9144th; }            // 1.09361329833771
inline double Meters2Miles( const double &m )        { return m*One1609Pt344th; }        // 0.000621371192237334

inline double KM2Meters( const double &km )            { return km*1000.0; }
inline double KM2CM( const double &km )                { return km*100000.0; }
inline double KM2MM( const double &km )                { return km*1000000.0; }
inline double KM2Inches( const double &km )            { return km*OnePt0000254th; }        // 39370.0787401575
inline double KM2Feet( const double &km )            { return km*OnePt0003048th; }        // 3280.83989501312
inline double KM2Yards( const double &km )            { return km*OnePt0009144th; }        // 1093.61329833771
inline double KM2Miles( const double &km )            { return km*One1Pt609344th; }        // 0.621371192237334

inline double Kph2Mph( const double &kph )            { return kph*One1Pt609344th; }        // 0.621371192237334
inline double Mph2Kph( const double &mph )            { return mph*1.609344; }
 
inline double Kph2Mps( const double &kph )            { return kph*One3point6th; }        // 1/3.6
inline double Mph2Mps( const double &mph )            { return mph*0.44704; }
inline double Fps2Mps( const double &fps )            { return fps*0.3048; }

inline double Mps2Mph( const double &mps )            { return mps*OnePt44704th; }        // 2.2369362920544
inline double Mps2Kph( const double &mps )            { return mps*3.6; }
inline double Mps2Fps( const double &mps )            { return mps*OnePt3048th; }            // 3.28083989501312

inline double Lbs2Kg( const double &lbs )            { return lbs*One2Pt20462262185th; }    // 0.453592369999748
inline double Kg2Lbs( const double &kg )            { return kg*2.20462262185; }

inline double LbForce2Newtons( const double &lbs )    { return lbs*4.44822161525; }
inline double Newtons2LbForce( const double &nt )    { return nt*One4Pt44822th; }        // 0.224808943100241
inline double FtLbs2NtMeters( const double &ftlbs )    { return ftlbs*OnePt737562th; }        // 1.35581794828961
inline double NtMeters2FtLbs( const double &ntm )    { return ntm*0.7375621493; }

inline double Gallons2Liters( const double &l )        { return l*3.78541178401; }
inline double Liters2Gallons( const double &g )        { return g*One3Pt785411th; }        // 0.264172052357451

inline double Radians2Degrees( const double &r )    { return r*Rad2Deg; }                // rad*180/Pi
inline double Degrees2Radians( const double &d )    { return d*Deg2Rad; }                // deg*Pi/180
inline double Rad2DegreesIfloat( const float &r )    { return double(r*fRad2Deg); }        // rad*180/Pi
inline double Deg2RadiansIfloat( const float &d )    { return double(d*fDeg2Rad); }        // deg*Pi/180
inline float  floatRadians2Degrees(const double &r)    { return float(r*Rad2Deg); }        // rad*180/Pi
inline float  floatDegrees2Radians(const double &d)    { return float(d*Deg2Rad); }        // deg*Pi/180
inline float  floatRad2Degrees( const float &r )    { return r*fRad2Deg; }                // rad*180/Pi
inline float  floatDeg2Radians( const float &d )    { return d*fDeg2Rad; }                // deg*Pi/180

Name: Anonymous 2011-04-21 2:55

ENTERPRISE-LEVEL SCALABLE REUSABLE LIBRARY

Name: Anonymous 2011-04-21 3:03

Now it's much shorter.

#define Pi 3.14159265358979323846264
#define TWO_Pi Pi*2.0
#define HALF_Pi Pi/2.0
#define QUARTER_Pi Pi/4.0
#define Deg2Rad Pi/180.0
#define Rad2Deg 180.0/Pi
#define fDeg2Rad static_cast(Deg2Rad)
#define fRad2Deg static_cast(Rad2Deg)
#define OneThird 1.0/3.0
#define One3point6th 1.0/3.6
#define OneTwelfth 1.0/12.0
#define OneThirtysixth 1.0/36.0
#define One1760th 1.0/1760
#define One5280th 1.0/5280
#define One63360th 1.0/63360.0
#define One25Pt4th 1.0/25.4// 0.0393700787401575mm -> inches
#define One2Pt54th 1.0/2.54// 0.393700787401575cm -> inches
#define OnePt0254th 1.0/0.0254// 39.3700787401575m  -> inches
#define OnePt0000254th 1.0/0.0000254// 39370.0787401575km -> inches
#define One2Pt20462262185th 1.0/2.20462262185// 0.453592369999748Lbs-> Kg
#define One304Pt8th 1.0/304.8// 0.00328083989501312mm -> feet
#define One30Pt48th 1.0/30.48// 0.0328083989501312cm -> feet
#define OnePt3048th 1.0/.3048// 3.28083989501312m  -> feet
#define OnePt0003048th 1.0/.0003048// 3280.83989501312km -> feet
#define One914Pt4th 1.0/914.4// 0.00109361329833771mm -> yards
#define One91Pt44th 1.0/91.44// 0.0109361329833771cm -> yards
#define OnePt9144th 1.0/.9144// 1.09361329833771m  -> yards
#define OnePt0009144th 1.0/.0009144// 1093.61329833771km -> yards
#define One1609344th 1.0/1609344// 0.000000621371192237334mm -> Miles
#define One160934Pt4th 1.0/160934.4// 0.00000621371192237334cm -> Miles
#define One1609Pt344th 1.0/1609.344// 0.000621371192237334m  -> Miles
#define One1Pt609344th 1.0/1.609344// 0.621371192237334km -> Miles
#define One4Pt44822th 1.0/4.44822161525// 0.224808943100241Nt -> LbForce
#define OnePt737562th 1.0/0.7375621493// 1.35581794828961FtLbs -> NtM
#define OnePt44704th 1.0/0.44704// 2.2369362920544Mps -> Mph
#define One3Pt785411th 1.0/3.78541178401// 0.264172052357451Liters -> Gallons

#define Inches2Feet( i )(i*OneTwelfth)// 1/12
#define Inches2Yards( i )(i*OneThirtysixth)// 1/36
#define Inches2Miles( i )(i*One63360th)// 1/63360.0
#define Inches2MM( i )(i*25.4)
#define Inches2CM( i )(i*2.54)
#define Inches2Meters( i )(i*.0254)
#define Inches2KM( i )(i*.0000254)

#define Feet2Inches( f )(f*12.0)
#define Feet2Yards( f )(f*OneThird)// 1/3
#define Feet2Miles( f )(f*One5280th)// 1/5280
#define Feet2MM( f )(f*304.8)
#define Feet2CM( f )(f*30.48)
#define Feet2Meters( f )(f*0.3048)
#define Feet2KM( f )(f*0.0003048)

#define Yards2Inches( y )(y*36.0)
#define Yards2Feet( y )(y*3.0)
#define Yards2Miles( y )(y*One1760th)// 1/1760.0
#define Yards2MM( y )(y*914.4)
#define Yards2CM( y )(y*91.44)
#define Yards2Meters( y )(y*.9144)
#define Yards2KM( y )(y*.0009144)

#define Miles2Inches( mi )(mi*63360.0)
#define Miles2Feet( mi )(mi*5280)
#define Miles2Yards( mi )(mi*1760.0)
#define Miles2MM( mi )(mi*1609344.0)
#define Miles2CM( mi )(mi*160934.4)
#define Miles2Meters( mi )(mi*1609.344)
#define Miles2KM( mi )(mi*1.609344)

#define MM2CM( mm )(mm*.1)
#define MM2Meters( mm )(mm*.001)
#define MM2KM( mm )(mm*.000001)
#define MM2Inches( mm )(mm*One25Pt4th)// 0.0393700787401575
#define MM2Feet( mm )(mm*One304Pt8th)// 0.00328083989501312
#define MM2Yards( mm )(mm*One914Pt4th)// 0.00109361329833771
#define MM2Miles( mm )(mm*One1609344th)// 0.000000621371192237334

#define CM2MM( cm )(cm*10.0)
#define CM2Meters( cm )(cm*.01)
#define CM2KM( cm )(cm*.00001)
#define CM2Inches( cm )(cm*One2Pt54th)// 0.393700787401575
#define CM2Feet( cm )(cm*One30Pt48th)// 0.0328083989501312
#define CM2Yards( cm )(cm*One91Pt44th)// 0.0109361329833771
#define CM2Miles( cm )(cm*One160934Pt4th)// 0.00000621371192237334

#define Meters2MM( m )(m*1000.0)
#define Meters2CM( m )(m*100.0)
#define Meters2KM( m )(m*.001)
#define Meters2Inches( m )(m*OnePt0254th)// 39.3700787401575
#define Meters2Feet( m )(m*OnePt3048th)// 3.28083989501312
#define Meters2Yards( m )(m*OnePt9144th)// 1.09361329833771
#define Meters2Miles( m )(m*One1609Pt344th)// 0.000621371192237334

#define KM2Meters( km )(km*1000.0)
#define KM2CM( km )(km*100000.0)
#define KM2MM( km )(km*1000000.0)
#define KM2Inches( km )(km*OnePt0000254th)// 39370.0787401575
#define KM2Feet( km )(km*OnePt0003048th)// 3280.83989501312
#define KM2Yards( km )(km*OnePt0009144th)// 1093.61329833771
#define KM2Miles( km )(km*One1Pt609344th)// 0.621371192237334

#define Kph2Mph( kph )(kph*One1Pt609344th)// 0.621371192237334
#define Mph2Kph( mph )(mph*1.609344)
 
#define Kph2Mps( kph )(kph*One3point6th)// 1/3.6
#define Mph2Mps( mph )(mph*0.44704)
#define Fps2Mps( fps )(fps*0.3048)

#define Mps2Mph( mps )(mps*OnePt44704th)// 2.2369362920544
#define Mps2Kph( mps )(mps*3.6)
#define Mps2Fps( mps )(mps*OnePt3048th)// 3.28083989501312

#define Lbs2Kg( lbs )(lbs*One2Pt20462262185th)// 0.453592369999748
#define Kg2Lbs( kg )(kg*2.20462262185)

#define LbForce2Newtons( lbs )(lbs*4.44822161525)
#define Newtons2LbForce( nt )(nt*One4Pt44822th)// 0.224808943100241
#define FtLbs2NtMeters( ftlbs )(ftlbs*OnePt737562th)// 1.35581794828961
#define NtMeters2FtLbs( ntm )(ntm*0.7375621493)

#define Gallons2Liters( l )(l*3.78541178401)
#define Liters2Gallons( g )(g*One3Pt785411th)// 0.264172052357451

#define Radians2Degrees( r )(r*Rad2Deg)// rad*180/Pi
#define Degrees2Radians( d )(d*Deg2Rad)// deg*Pi/180
#define Rad2DegreesIfloat( r )(double(r*fRad2Deg))// rad*180/Pi
#define Deg2RadiansIfloat( d )(double(d*fDeg2Rad))// deg*Pi/180
#define floatRadians2Degrees(r)(float(r*Rad2Deg))// rad*180/Pi
#define floatDegrees2Radians(d)(float(d*Deg2Rad))// deg*Pi/180
#define floatRad2Degrees( r )(r*fRad2Deg)// rad*180/Pi
#define floatDeg2Radians( d )(d*fDeg2Rad)// deg*Pi/180

Name: Anonymous 2011-04-21 3:06

>>3
Is there a way, to get rid of annoying "#define" over 9000 times?

Name: Anonymous 2011-04-21 3:08

>>4

sed 's/^/#define /' | gcc ...

Name: Anonymous 2011-04-21 3:51

I had a very destructive relationship with this bad guy about five years ago . He was two years younger than me, he’s good looking, tall, and talented. He was also a student journalist like me when we met. There was no formal courtship between us and what we had was a whirlwind romance. Three months we’re okay and the relationship was blissful especially for me…well, I thought I was a wall flower and it was a boon for someone like me to get noticed by someone like him…so I thought. But the magic worn off in the preceding months. He tormented me through verbal abuse, he tried to change my outfits, my make up, my hair cut, and almost everything about me. He thought at times I was ugly because I had full lips… he was always surrounded by younger and prettier women. And to my misery these women always try to pursue him, seduce him, touch him in front of me…and one time caught him with his so-called female best friend after their movie date. While there was I, thinking he attended a rehearsal for a dance to be presented in his physical education class…I was fooled. That was truly devastating for me. My self esteem crumbled, I was so insecure…he always tell me how possessive and jealous I have become, that I am a people-pleaser.well, I became one. He literally never greeted me during my birthday and never showed up because he was mad at me. Instead he told me, we’re better off as friends and later, popped the statement he wanted out because he no longer love me. I begged off not win him back I was tired of hurting I just want to know what happened, I was literally on my feet because I wanted to know why. But just like that he dumped, just like that, that easy. My heart, my soul, and my spirit were all crushed that I wanted to die.
However, studies and career wise, the break up proved beneficial on my part . Everything went by smoothly in these two aspects.But when night time comes and I’m left with myself struggling and dying inside. I started to rebel to be bitter,I became a player myself and worse had two sexual relations with two guys…that was five years of confusion, grief,and hopelessness. Until another inopportune event came, the death of my best friend. It had been God’s wake up call to me because my best friend committed suicide because of her “bad boy” ex boyfriend. That guy pushed her to kill herself, asked her to literally hang herself to prove how much she loves him (she was then on the verge of an emotional and mental breakdown and did it). I was grief stricken, what happened lead me to learn about my self destruction and what I have done these past few years. I realized I don’t have to reach that point no matter how distressed and depressed I was. It was in a way an eye opener too that I still have the chance to get my self together. I left who I was “playing fire” with at that time and tried to see thing through, salvage whatever hope I had at my disposal to make up for what I did to myself…gradually I started to pray again and attend church as often as I can.I sought professional help to therapist friends too.I took my job seriously and learned to love it. I enrolled at my Alma mater and pursued a graduate school course. and now,in a year, am about to embark on my thesis and finish soon.I wrote articles, poetry,sketched pictures again. I contacted my old friends whom I forgot throughout my ordeal and my depression.I apologized to people I hurt, reconnect with my family especially my mom and made peace with myself. I know that I can’t reverse what I did to my life, and there are times I slip…there are also setbacks towards my desire for change but I continue to fight to achieve it. life must go on, all I can do is to treat my self better, the ones I love, and other people.I try to live the life and the things that which my friend missed and won’t be able to do anymore. I condition my mind and my heart that there is always something to look forward to everyday, something that would make life worthwhile and happy. I’m still single as of now, I met him (the bad guy) recently, and he said sorry and he still has feelings for me. It’s okay though, but I won’t run after him anymore because I am now aware that I am not anybody’s doormat, not his rag. Love might just be there waiting in the wings and I believe I am fated by God to be with a man who would love me for me. He just haven’t come yet but I’m willing to wait.

Name: Anonymous 2011-04-21 3:53

:D
rofl!
isn't that a riot!!???? Just found that on a Jesus Freex site. Make it a meme. Skim it maybe it already is-- Meh.. :P

Name: Anonymous 2011-04-21 3:57

Give me the MS Paint JPG!!!!!!!!! ... ]:D

Name: Anonymous 2011-04-21 3:58

SICP! SICP!

Name: Anonymous 2011-04-21 4:03

>>4
#define D #define

Name: Anonymous 2011-04-21 4:07

>>10
doesn't work

Name: Anonymous 2011-04-21 4:09

SiiiiiiiiiIIIIIIIIIIIIC P?

Name: Anonymous 2011-04-21 4:11

fart fart fart

Name: Anonymous 2011-04-21 4:12

SICP!

Name: Anonymous 2011-04-21 4:13

No SICP pic? Denied?

Name: Anonymous 2011-04-21 4:15

OK fine save it then for a later time I'm going to sleep. Bedtime!

Name: Anonymous 2011-04-21 4:23

>>6
God
What is "God"?

Name: Anonymous 2011-04-21 4:35

>>17
Baby don't hurt me.
Don't hurt me.
No more.

Name: Anonymous 2011-04-21 5:54

>>3
Lol, your so moran. Inches2Feet(12 + 12) == 13, ha ha ha.

Name: Anonymous 2011-04-21 6:03

That was ENTERPRISE-Quality!


(define-values
  (π 2π 1/2π 1/4π)
  (let ((π (atan 0 -1)))
    (values π (* 2 π) (/ π 2) (/ π 4))))

(define-values
  (deg2rad rad2deg)
  (values (/ π 180) (/ 180 π)))

(define-syntax define-inline
  (syntax-rules ()
    ((_ (n . x) b)
     (begin
       (define (proc . x) b)
       (define-syntax (n stx)
         (syntax-case stx ()
           ((n . x) #'b)
           (n (identifier? #'n) #'proc)))))))

(define-syntax define-inlines
  (syntax-rules ()
    ((_ (n x b) ...)
     (begin (define-inline (n . x) b) ...))))

(define-syntax define/mults
  (syntax-rules ()
    ((_ (n y) ...)
     (define-inlines (n (x) (* x y)) ...))))

(define-syntax (define/conv stx)
  (define (id-append stx x y)
    (datum->syntax
     stx
     (string->symbol
      (string-append
       (symbol->string (syntax->datum x)) "->"
       (symbol->string (syntax->datum y))))))
  (syntax-case stx ()
    ((_ n m b)
     (let* ((b (syntax->datum #'b)) (1/b (/ b)))
       (with-syntax ((n->m (id-append #'n #'n #'m))
                     (m->n (id-append #'n #'m #'n)))
         #`(define/mults (n->m #,b) (m->n #,1/b)))))))

(define-syntax (define/meters stx)
  (define (id-append stx x y)
    (datum->syntax stx (string->symbol (string-append (symbol->string x) (symbol->string y)))))
  (syntax-case stx ()
    ((_ n b)
     (let* ((bb (inexact->exact (syntax->datum #'b))) (bb/10 (/ bb 10)) (bb/1000 (/ bb 1000)) (bb/1e6 (/ bb 1000000)))
       #`(begin (define/conv n millimeters #,bb)
                (define/conv n centimeters #,bb/10)
                (define/conv n meters #,bb/1000)
                (define/conv n kilometers #,bb/1e6))))))

(define/conv feet inches 12)
(define/conv yards inches 36)
(define/conv yards feet 3)
(define/conv miles inches 63360)
(define/conv miles yards 1760)
(define/conv miles feet 5280)

(define/meters inches 25.4)
(define/meters feet  304.8)
(define/meters yards 914.4)
(define/meters miles 1609344)

(define/conv millimeters centimeters .1)
(define/conv millimeters meters .001)
(define/conv millimeters kilometers 1e-6)

(define/conv centimeters millimeters 10)
(define/conv centimeters meters .1)
(define/conv centimeters kilometers 1e-5)

(define/conv meters millimeters 1000)
(define/conv meters centimeters 100)
(define/conv meters kilometers 1e-3)

(define/conv kilometers millimeters 1e6)
(define/conv kilometers centimeters 1e5)
(define/conv kilometers meters 1000)

(define/conv mph km/h 1.609344)
(define/conv m/s km/h 3.6)
(define/conv mph m/s .44704)
(define/conv fps m/s .3048)

(define/conv kg lbs 2.20462262185)

(define/conv lbforce newtons 4.44822161525)
(define/conv newton/meters feet/lbs .7375621493)

(define/conv gallons liters 3.78541178401)

(define/mults
  (rad->deg rad2deg)
  (deg->rad deg2rad))

Name: Anonymous 2011-04-21 6:06

>>20
Disregard the meters part, it's just

(define/conv centimeters millimeters 10)
(define/conv meters millimeters 1000)
(define/conv meters centimeters 100)
(define/conv kilometers millimeters 1e6)
(define/conv kilometers centimeters 1e5)
(define/conv kilometers meters 1000)

Name: Anonymous 2011-04-21 7:05

>>19
Sorry. Forgot that sepples macros're textual.

Name: Anonymous 2011-04-21 7:09

>>20
You still copypaste tons of define/convm, while in Common Lisp it's easy to define list-processing macro

(w/conv
  feet inches 12
  yards inches 36
  yards feet 3
  miles inches 63360
  miles yards 1760
  miles feet 5280)

Name: Anonymous 2011-04-21 7:16

>>23
(define-syntax-rule (define/convs (n m x) ...) (begin (define/conv n m x) ...))
(define/convs
  (feet inches 12)
  (yards inches 36)
  (yards feet 3)
  (miles inches 63360)
  (miles feet 5280))


Sorry for being too lazy to be lazy!

Name: Anonymous 2011-04-21 7:40

OMG OPTIMIZED

(define-syntax-rule (define-inline (n . x) . b)
  (begin (define (inlined . x) . b)
         (define-syntax (n stx)
           (syntax-case stx ()
             ((n . x) #'(begin . b))
             (n (identifier? #'n) #'inlined)))))

(define-syntax (define/conv stx)
  (define (id-append stx x y)
    (datum->syntax
     stx
     (string->symbol
      (string-append
       (symbol->string (syntax->datum x)) "->"
       (symbol->string (syntax->datum y))))))
  (syntax-case stx ()
    ((_ n m b)
     (let* ((b (inexact->exact (syntax->datum #'b))) (1/b (/ b)))
       (with-syntax ((n->m (id-append #'n #'n #'m))
                     (m->n (id-append #'n #'m #'n)))
         #`(define/mults (n->m #,b) (m->n #,1/b)))))))

(define-syntax (define/meters stx)
  (syntax-case stx ()
    ((_ n b)
     (let* ((bb (inexact->exact (syntax->datum #'b))) (bb/10 (/ bb 10)) (bb/1000 (/ bb 1000)) (bb/1e6 (/ bb 1000000)))
       #`(begin (define/conv n millimeters #,bb)
                (define/conv n centimeters #,bb/10)
                (define/conv n meters #,bb/1000)
                (define/conv n kilometers #,bb/1e6))))))

(define-syntax-rule (define-inlines (n x . b) ...)
  (begin (define-inline (n . x) . b) ...))
(define-syntax-rule (define/mults (n y) ...)
  (define-inlines (n (x) (* x y)) ...))
(define-syntax-rule (define/meters* (n b) ...)
  (begin (define/meters n b) ...))
(define-syntax-rule (define/convs (n m x) ...)
  (begin (define/conv n m x) ...))

(define-values
  (π 2π 1/2π 1/4π deg2rad rad2deg)
  (let ((π (atan 0 -1)))
    (values π (* 2 π) (/ π 2) (/ π 4) (/ π 180) (/ 180 π))))

(define/mults
  (rad->deg rad2deg)
  (deg->rad deg2rad))

(define/meters*
  (inches 25.4)
  (feet 304.8)
  (yards 914.4)
  (miles 1609344))

(define/convs
  (feet inches 12)
  (yards inches 36)
  (yards feet 3)
  (miles inches 63360)
  (miles feet 5280)
  (centimeters millimeters 10)
  (meters millimeters 1000)
  (meters centimeters 100)
  (kilometers millimeters 1e6)
  (kilometers centimeters 1e5)
  (kilometers meters 1000)
  (mph km/h 1.609344)
  (m/s km/h 3.6)
  (mph m/s .44704)
  (fps m/s .3048)
  (kg lbs 2.20462262185)
  (lbforce newtons 4.44822161525)
  (newton/meters feet/lbs .7375621493)
  (gallons liters 3.78541178401))

Name: Anonymous 2011-04-21 8:47

I wrote some similar CL macros for unit conversion. It was so easy and tiny.

Name: Anonymous 2011-04-21 9:00

>>26
Less than 13 lines? I don't think so.

Name: Anonymous 2011-04-21 9:17

/r/ JAVA version.

Name: Anonymous 2011-04-21 11:31

/r/ Perl version
>>28 Fix'd that fer ya, my man.

Name: Anonymous 2011-04-21 11:43

>>27
Macro itself, quite possibly.
Actual unit listing? No, one unit definition per line (or s-exp).
I'd have to go dig through my old code for the exact implementation, but it wasn't anything too special, just your usual CL macro.

Name: Anonymous 2011-04-21 12:51

>>30
Oh, ok then.

Don't change these.
Name: Email:
Entire Thread Thread List